This notebook covers the Hackathon problem.
Problem Statement: Develop a recommendation model from the given 2 datasets.
Datasets given: Electronics Sales & Modcloth Sales.
For Recommendation, I have made 3 criteria:
a. Recommendation based on Ratings
b. Recommendation based on Demand of Items/Number of Units Sold
c. Recommendation based on Market Basket Analysis (using Apriori)
We will be making use of below libraries:
* Pandas: for reading & manipulating data via forming DataFrame <br>
* Plotly: for data visualisation <br>
* Mlxtend: for making association rules (market basket analysis) between items and categories
"""installing libraries"""
# !pip install plotly
# !pip install mlxtend
'installing libraries'
import pandas as pd
import plotly.express as px
from mlxtend.frequent_patterns import apriori, association_rules
from mlxtend.preprocessing import TransactionEncoder
import mlxtend
import numpy as np
from scipy.sparse import csr_matrix
from sklearn.neighbors import NearestNeighbors
"""Reading the Datasets: We form dataframes from the 2 .csv files"""
raw_electronics_db = pd.read_csv("electronics.csv")
raw_modcloth_db = pd.read_csv("modcloth.csv")
"""Dataframe of Electronics database"""
raw_electronics_db.head()
| item_id | user_id | rating | timestamp | model_attr | category | brand | year | user_attr | split | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 5.0 | 1999-06-13 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 1 | 0 | 1 | 5.0 | 1999-06-14 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 2 | 0 | 2 | 3.0 | 1999-06-17 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 3 | 0 | 3 | 1.0 | 1999-07-01 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 4 | 0 | 4 | 2.0 | 1999-07-06 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
"""Dataframe of Modcloth database"""
raw_modcloth_db.head()
| item_id | user_id | rating | timestamp | size | fit | user_attr | model_attr | category | brand | year | split | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 7443 | Alex | 4 | 2010-01-21 08:00:00+00:00 | NaN | NaN | Small | Small | Dresses | NaN | 2012 | 0 |
| 1 | 7443 | carolyn.agan | 3 | 2010-01-27 08:00:00+00:00 | NaN | NaN | NaN | Small | Dresses | NaN | 2012 | 0 |
| 2 | 7443 | Robyn | 4 | 2010-01-29 08:00:00+00:00 | NaN | NaN | Small | Small | Dresses | NaN | 2012 | 0 |
| 3 | 7443 | De | 4 | 2010-02-13 08:00:00+00:00 | NaN | NaN | NaN | Small | Dresses | NaN | 2012 | 0 |
| 4 | 7443 | tasha | 4 | 2010-02-18 08:00:00+00:00 | NaN | NaN | Small | Small | Dresses | NaN | 2012 | 0 |
"""Number of purchases made by every user"""
raw_electronics_db.user_id.value_counts()
142967 41
30661 38
89185 37
80476 34
46878 34
..
702412 1
692171 1
696265 1
694216 1
0 1
Name: user_id, Length: 1157633, dtype: int64
"""cases where the user has purchased only 1 item"""
raw_electronics_db.user_id.value_counts()[
raw_electronics_db.user_id.value_counts() == 1
]
533596 1
944283 1
374253 1
252184 1
196866 1
..
702412 1
692171 1
696265 1
694216 1
0 1
Name: user_id, Length: 1054823, dtype: int64
"""total number of users in Modcloth database"""
raw_modcloth_db.user_id.value_counts()
Sarah 250
Amanda 204
jennifer 198
Laura 197
Jennifer 191
...
contact 1
lisamarie1019 1
auraroy 1
kaylabr 1
lenab 1
Name: user_id, Length: 44783, dtype: int64
"""cases where the user has purchased only 1 item"""
raw_modcloth_db.user_id.value_counts()[raw_modcloth_db.user_id.value_counts() == 1]
ram.z.rach 1
kyliemwilliams074 1
emma.c.newhall 1
ashlatash2297 1
Manager 1
..
contact 1
lisamarie1019 1
auraroy 1
kaylabr 1
lenab 1
Name: user_id, Length: 30307, dtype: int64
"""For electronics Database"""
raw_electronics_db
| item_id | user_id | rating | timestamp | model_attr | category | brand | year | user_attr | split | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 5.0 | 1999-06-13 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 1 | 0 | 1 | 5.0 | 1999-06-14 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 2 | 0 | 2 | 3.0 | 1999-06-17 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 3 | 0 | 3 | 1.0 | 1999-07-01 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| 4 | 0 | 4 | 2.0 | 1999-07-06 | Female | Portable Audio & Video | NaN | 1999 | NaN | 0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1292949 | 9478 | 1157628 | 1.0 | 2018-09-26 | Female | Headphones | Etre Jeune | 2017 | NaN | 0 |
| 1292950 | 9435 | 1157629 | 5.0 | 2018-09-26 | Female | Computers & Accessories | NaN | 2017 | NaN | 0 |
| 1292951 | 9305 | 1157630 | 3.0 | 2018-09-26 | Female | Computers & Accessories | NaN | 2016 | NaN | 0 |
| 1292952 | 9303 | 1157631 | 5.0 | 2018-09-29 | Male | Headphones | NaN | 2018 | NaN | 0 |
| 1292953 | 9478 | 1157632 | 1.0 | 2018-10-01 | Female | Headphones | Etre Jeune | 2017 | Female | 0 |
1292954 rows × 10 columns
"""missing values per column are as below"""
raw_electronics_db.isna().sum()
item_id 0 user_id 0 rating 0 timestamp 0 model_attr 0 category 0 brand 961834 year 0 user_attr 1118830 split 0 dtype: int64
"""for column brand"""
raw_electronics_db.brand.value_counts().head()
Bose 29222 Logitech 29203 Sony 20360 Mpow 17477 EldHus 16530 Name: brand, dtype: int64
'''Replacing the NA values in (Gender) user_attr column with "NA"'''
raw_electronics_db.brand.fillna("Other", inplace=True)
"""for column user_attr"""
raw_electronics_db.user_attr.value_counts()
Male 87424 Female 86700 Name: user_attr, dtype: int64
'''Replacing the NA values in (Gender) user_attr column with "NA"'''
raw_electronics_db.user_attr.fillna("NA", inplace=True)
raw_electronics_db.isna().sum()
item_id 0 user_id 0 rating 0 timestamp 0 model_attr 0 category 0 brand 0 year 0 user_attr 0 split 0 dtype: int64
raw_modcloth_db.isna().sum()
item_id 0 user_id 1 rating 0 timestamp 0 size 21760 fit 18506 user_attr 8367 model_attr 0 category 0 brand 73980 year 0 split 0 dtype: int64
raw_modcloth_db.brand.fillna("Other", inplace=True)
"""We will not be making use of columns size, fit user_attr, so we will ignore those columns"""
'We will not be making use of columns size, fit user_attr, so we will ignore those columns'
select_electronics_db = raw_electronics_db[
["item_id", "user_id", "rating", "timestamp", "category", "brand"]
]
select_modcloth_db = raw_modcloth_db[
["item_id", "user_id", "rating", "timestamp", "category", "brand"]
]
"""Consolidated DataFrame"""
consolidated_db = select_electronics_db.append(select_modcloth_db)
"""Let us check the data types of the columns"""
consolidated_db.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 1392847 entries, 0 to 99892 Data columns (total 6 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 item_id 1392847 non-null int64 1 user_id 1392846 non-null object 2 rating 1392847 non-null float64 3 timestamp 1392847 non-null object 4 category 1392847 non-null object 5 brand 1392847 non-null object dtypes: float64(1), int64(1), object(4) memory usage: 74.4+ MB
"""from the above we see that timestamp is not in datetime datatype, hence we convert it to datetime"""
consolidated_db.timestamp = [str(i)[:10] for i in consolidated_db.timestamp.tolist()]
consolidated_db.timestamp = pd.to_datetime(consolidated_db.timestamp)
"""Let us form columns of Year and Month for our further analysis"""
consolidated_db.insert(4, "Month", pd.DatetimeIndex(consolidated_db.timestamp).month)
consolidated_db.insert(5, "Year", pd.DatetimeIndex(consolidated_db.timestamp).year)
consolidated_db.head()
| item_id | user_id | rating | timestamp | Month | Year | category | brand | |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 5.0 | 1999-06-13 | 6 | 1999 | Portable Audio & Video | Other |
| 1 | 0 | 1 | 5.0 | 1999-06-14 | 6 | 1999 | Portable Audio & Video | Other |
| 2 | 0 | 2 | 3.0 | 1999-06-17 | 6 | 1999 | Portable Audio & Video | Other |
| 3 | 0 | 3 | 1.0 | 1999-07-01 | 7 | 1999 | Portable Audio & Video | Other |
| 4 | 0 | 4 | 2.0 | 1999-07-06 | 7 | 1999 | Portable Audio & Video | Other |
"""Let us check the period for which we have the data"""
consolidated_db.sort_values(by="timestamp")
| item_id | user_id | rating | timestamp | Month | Year | category | brand | |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 5.0 | 1999-06-13 | 6 | 1999 | Portable Audio & Video | Other |
| 1 | 0 | 1 | 5.0 | 1999-06-14 | 6 | 1999 | Portable Audio & Video | Other |
| 2 | 0 | 2 | 3.0 | 1999-06-17 | 6 | 1999 | Portable Audio & Video | Other |
| 3 | 0 | 3 | 1.0 | 1999-07-01 | 7 | 1999 | Portable Audio & Video | Other |
| 4 | 0 | 4 | 2.0 | 1999-07-06 | 7 | 1999 | Portable Audio & Video | Other |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 99881 | 47325 | rachel | 1.0 | 2019-06-26 | 6 | 2019 | Outerwear | Other |
| 99885 | 77949 | rachel | 5.0 | 2019-06-26 | 6 | 2019 | Bottoms | Other |
| 99891 | 71607 | amy | 3.0 | 2019-06-27 | 6 | 2019 | Outerwear | Jack by BB Dakota |
| 99890 | 67194 | Janice | 5.0 | 2019-06-27 | 6 | 2019 | Dresses | Other |
| 99892 | 119732 | sarah | 3.0 | 2019-06-29 | 6 | 2019 | Dresses | Other |
1392847 rows × 8 columns
"""For counting purpose, we will create a column called as count with element as 1"""
consolidated_db["count"] = 1
consolidated_db.head()
| item_id | user_id | rating | timestamp | Month | Year | category | brand | count | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 5.0 | 1999-06-13 | 6 | 1999 | Portable Audio & Video | Other | 1 |
| 1 | 0 | 1 | 5.0 | 1999-06-14 | 6 | 1999 | Portable Audio & Video | Other | 1 |
| 2 | 0 | 2 | 3.0 | 1999-06-17 | 6 | 1999 | Portable Audio & Video | Other | 1 |
| 3 | 0 | 3 | 1.0 | 1999-07-01 | 7 | 1999 | Portable Audio & Video | Other | 1 |
| 4 | 0 | 4 | 2.0 | 1999-07-06 | 7 | 1999 | Portable Audio & Video | Other | 1 |
"""Let us check how many times each item has been bought & the average rating per item"""
buy_count = consolidated_db.groupby(by="item_id", as_index=False).agg(
{"count": pd.Series.sum}
)
buy_count.rename(columns={"count": "total_sold_qty"}, inplace=True)
buy_count.head()
| item_id | total_sold_qty | |
|---|---|---|
| 0 | 0 | 118 |
| 1 | 1 | 58 |
| 2 | 2 | 3404 |
| 3 | 3 | 155 |
| 4 | 4 | 11 |
"""Let us create a function to get category of an item"""
item_category = consolidated_db[["item_id","category"]].drop_duplicates()
def get_item_category(item_id):
return item_category[item_category.item_id == f"{item_id}"].values[0][1]
"""Let us check the buy count trend over the years"""
time_df = consolidated_db.groupby(by="timestamp", as_index=False).agg(
{"count": pd.Series.sum}
)
"""We will check the number of sales over time"""
fig = px.line(data_frame=time_df, x="timestamp", y="count")
fig.update_layout(
title_text="Number of purchases over time", xaxis_title="Time", yaxis_title="Count"
)
fig.show()
"""Let us check the sales performance of the categories every month"""
monthly_category_sale = consolidated_db.groupby(
by=["category", "Month"], as_index=False
).agg({"count": pd.Series.sum})
fig = px.line(data_frame=monthly_category_sale, x="Month", y="count", color="category")
fig.update_layout(title_text="Category Sales Performance over Months")
fig.show()
"""Merging the dataframes"""
consolidated_db2 = pd.merge(consolidated_db, buy_count, on="item_id")
"""Considering cases where the sale of item is above 50 units"""
consolidated_db2 = consolidated_db2[consolidated_db2.total_sold_qty > 50]
list_category = list(consolidated_db2.category.unique())
consolidated_db2.category.value_counts()
Headphones 341966 Computers & Accessories 294515 Camera & Photo 161712 Accessories & Supplies 152388 Portable Audio & Video 132821 Tops 30522 Dresses 30033 Car Electronics & GPS 29147 Television & Video 27707 Home Audio 23034 Bottoms 21960 Wearable Technology 13647 Security & Surveillance 9315 Outerwear 6380 Name: category, dtype: int64
brand_df = consolidated_db2.groupby(by=["category", "brand"], as_index=False).agg(
{"count": pd.Series.sum}
)
brand_df["count"] = 1
brand_df = brand_df.groupby(by="category", as_index=False).agg({"count": pd.Series.sum})
category_check = brand_df.sort_values(by="count", ascending=False)
"""Since one of the brand names in Others, we can substract 1 from each category to get the accurate count of brand names"""
category_check["count"] = category_check["count"] - 1
category_check
| category | count | |
|---|---|---|
| 4 | Computers & Accessories | 28 |
| 2 | Camera & Photo | 24 |
| 6 | Headphones | 20 |
| 9 | Portable Audio & Video | 15 |
| 0 | Accessories & Supplies | 11 |
| 11 | Television & Video | 8 |
| 3 | Car Electronics & GPS | 7 |
| 5 | Dresses | 7 |
| 7 | Home Audio | 6 |
| 12 | Tops | 5 |
| 1 | Bottoms | 3 |
| 8 | Outerwear | 3 |
| 10 | Security & Surveillance | 3 |
| 13 | Wearable Technology | 1 |
"""Let us form database of products sold in the past 2 years"""
past_2_years = consolidated_db2[consolidated_db2.timestamp > "2016-12-31"]
past_2_years.head()
| item_id | user_id | rating | timestamp | Month | Year | category | brand | count | total_sold_qty | |
|---|---|---|---|---|---|---|---|---|---|---|
| 3339 | 2 | 919978 | 5.0 | 2017-01-04 | 1 | 2017 | Headphones | Other | 1 | 3404 |
| 3340 | 2 | 919979 | 2.0 | 2017-01-04 | 1 | 2017 | Headphones | Other | 1 | 3404 |
| 3341 | 2 | 922707 | 5.0 | 2017-01-07 | 1 | 2017 | Headphones | Other | 1 | 3404 |
| 3342 | 2 | 922979 | 5.0 | 2017-01-08 | 1 | 2017 | Headphones | Other | 1 | 3404 |
| 3343 | 2 | 922980 | 1.0 | 2017-01-08 | 1 | 2017 | Headphones | Other | 1 | 3404 |
"""over-all item dataframe (1999 to 2019)"""
ovr_item_df = consolidated_db2.groupby(
by=["category", "item_id", "brand", "total_sold_qty"], as_index=False
).agg({"rating": pd.Series.mean})
ovr_item_df.rating = ovr_item_df.rating.round(2)
ovr_item_df = ovr_item_df.sort_values(by="rating", ascending=False)
"""last 2 years item dataframe (2017 to 2019)"""
ovr_2_item_df = past_2_years.groupby(
by=["category", "item_id", "brand", "total_sold_qty"], as_index=False
).agg({"rating": pd.Series.mean})
ovr_2_item_df.rating = ovr_2_item_df.rating.round(2)
ovr_2_item_df = ovr_2_item_df.sort_values(by="rating", ascending=False)
def top5_item_rating(category_input):
"""this function gives upto top 5 (or less) items in a given category based on rating in descending order"""
temp_top5_rating = ovr_item_df[ovr_item_df.category == category_input].head(5)
return [
category_input,
temp_top5_rating.item_id.tolist(),
temp_top5_rating.brand.tolist(),
temp_top5_rating.rating.tolist(),
]
print("Recommending Items based on their ratings received from 1999 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for i in range(14):
item_list = top5_item_rating(list_category[i])
df = pd.DataFrame(
{"Product": item_list[1], "Brand": item_list[2], "Rating": item_list[3]}
)
print(f"For Category:{item_list[0]}")
print()
print(f"{df}")
print("_______________________________")
print()
print()
Recommending Items based on their ratings received from 1999 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category:Portable Audio & Video Product Brand Rating 0 1647 Other 4.99 1 3214 Other 4.84 2 2667 Other 4.78 3 5802 Other 4.71 4 7715 Other 4.69 _______________________________ For Category:Computers & Accessories Product Brand Rating 0 4050 Other 4.90 1 4966 Plemo 4.90 2 5607 Other 4.84 3 7382 Other 4.83 4 9392 Other 4.82 _______________________________ For Category:Headphones Product Brand Rating 0 4576 EldHus 4.87 1 4413 Other 4.79 2 4320 Other 4.79 3 4013 Other 4.75 4 4584 Other 4.74 _______________________________ For Category:Camera & Photo Product Brand Rating 0 2513 Other 5.00 1 8484 Canon 4.91 2 7460 Other 4.88 3 4283 Fujifilm 4.88 4 4367 Other 4.88 _______________________________ For Category:Accessories & Supplies Product Brand Rating 0 3103 Other 4.89 1 7570 Other 4.88 2 3672 Other 4.88 3 7163 ebasy 4.87 4 5769 Other 4.85 _______________________________ For Category:Television & Video Product Brand Rating 0 5030 Other 4.72 1 476 Panasonic 4.69 2 9366 Other 4.66 3 8177 Other 4.66 4 2462 Other 4.56 _______________________________ For Category:Car Electronics & GPS Product Brand Rating 0 4659 Other 4.96 1 1991 Other 4.87 2 3498 Other 4.86 3 3300 Other 4.81 4 5559 Other 4.74 _______________________________ For Category:Home Audio Product Brand Rating 0 1546 Other 4.80 1 3443 Other 4.76 2 7384 Other 4.73 3 811 Other 4.73 4 1006 Other 4.70 _______________________________ For Category:Security & Surveillance Product Brand Rating 0 4027 Other 4.67 1 5031 Other 4.65 2 1840 Other 4.50 3 3754 Other 4.49 4 2687 Other 4.47 _______________________________ For Category:Wearable Technology Product Brand Rating 0 4968 Other 4.80 1 7759 Other 4.37 2 8752 Other 4.31 3 5033 Other 4.27 4 6438 Other 4.17 _______________________________ For Category:Dresses Product Brand Rating 0 154064 ModCloth 4.78 1 142983 Other 4.67 2 143686 Other 4.65 3 110169 Ryu 4.63 4 112559 Other 4.62 _______________________________ For Category:Outerwear Product Brand Rating 0 135555 ModCloth 4.61 1 123500 ModCloth 4.54 2 35272 Other 4.52 3 129113 Steve Madden 4.51 4 27439 Steve Madden 4.48 _______________________________ For Category:Bottoms Product Brand Rating 0 133539 Miss Candyfloss 4.76 1 144572 Other 4.74 2 153454 ModCloth 4.62 3 141880 ModCloth 4.61 4 148257 ModCloth 4.61 _______________________________ For Category:Tops Product Brand Rating 0 67022 Out of Print 4.79 1 143764 Daisey Natives 4.74 2 70230 Kin Ship 4.73 3 122266 Kin Ship 4.72 4 116736 Other 4.64 _______________________________
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
items_excel_df = pd.DataFrame(columns=["Recommendation_System_Type", "Category" , "Product", "Brand","Rating", "Sales"])
for i in range(14):
item_list = top5_item_rating(list_category[i])
df = pd.DataFrame(
{"Recommendation_System_Type":"Overall Rating", "Category": item_list[0], "Product": item_list[1], "Brand": item_list[2], "Rating": item_list[3]}
)
items_excel_df = items_excel_df.append(df)
brand_df = (
consolidated_db2.groupby(by=["category", "brand"], as_index=False)
.agg({"rating": pd.Series.mean})
.sort_values(by="rating", ascending=False)
)
"""We will not be considering the Other label in the brands column"""
brand_df = brand_df[brand_df.brand != "Other"]
brand_df.rating = brand_df.rating.round(2)
def top5_brands_rating(category_name):
"""This function returns a list of top brands and their ratings upon entering the category"""
temp_df_1 = brand_df[brand_df.category == category_name].head()
return [category_name, temp_df_1.brand.tolist(), temp_df_1.rating.tolist()]
def top_products_based_on_brand(category_name, brand_name):
"""This function prints dataframe of items and their ratings upon entering the category and brand"""
temp_df_2 = ovr_item_df[
(ovr_item_df.category == category_name) & (ovr_item_df.brand == brand_name)
].head()
item_list = temp_df_2.item_id.tolist()
rating_list = temp_df_2.rating.tolist()
df = pd.DataFrame({"Item_ID": item_list, "Rating": rating_list})
print(df)
print("Recommending Items as per Top Brands from 1999 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for k in range(14):
print(f"For Category: {list_category[k]}, top brands recommended are:\n")
sol = top5_brands_rating(list_category[k])
for j in range(len(sol[1])):
brand_id = sol[1][j]
brand_rating = sol[2][j]
print(f"Brand Rank {j+1}: {brand_id}")
print(f"Brand Rating: {brand_rating}")
print()
top_products_based_on_brand(list_category[k], brand_id)
print("_______________________________")
print("-------------------------------")
print()
print(
"________________________________________________________________________________________________"
)
print(
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)
print()
Recommending Items as per Top Brands from 1999 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category: Portable Audio & Video, top brands recommended are: Brand Rank 1: Mpow Brand Rating: 4.48 Item_ID Rating 0 5974 4.49 1 5748 4.47 _______________________________ ------------------------------- Brand Rank 2: Bose Brand Rating: 4.43 Item_ID Rating 0 5171 4.51 1 5273 4.48 2 5156 4.47 3 7022 4.41 4 3195 4.37 _______________________________ ------------------------------- Brand Rank 3: Apple Brand Rating: 4.35 Item_ID Rating 0 1139 4.35 _______________________________ ------------------------------- Brand Rank 4: DBPOWER Brand Rating: 4.16 Item_ID Rating 0 4009 4.20 1 2864 4.00 2 4079 3.46 _______________________________ ------------------------------- Brand Rank 5: Logitech Brand Rating: 4.07 Item_ID Rating 0 1948 4.07 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Computers & Accessories, top brands recommended are: Brand Rank 1: Plemo Brand Rating: 4.61 Item_ID Rating 0 4966 4.90 1 6839 4.76 2 4869 4.75 3 3258 4.75 4 3916 4.66 _______________________________ ------------------------------- Brand Rank 2: Cooper Cases Brand Rating: 4.55 Item_ID Rating 0 8655 4.82 1 9089 4.54 2 9203 4.53 3 3818 4.18 _______________________________ ------------------------------- Brand Rank 3: Fintie Brand Rating: 4.52 Item_ID Rating 0 5226 4.82 1 7812 4.78 2 4898 4.72 3 5245 4.71 4 5123 4.69 _______________________________ ------------------------------- Brand Rank 4: Apple Brand Rating: 4.43 Item_ID Rating 0 385 4.70 1 5405 4.65 2 4302 4.52 3 6562 4.51 4 5557 4.46 _______________________________ ------------------------------- Brand Rank 5: EldHus Brand Rating: 4.43 Item_ID Rating 0 1549 4.60 1 4369 4.50 2 2863 4.43 3 4144 4.07 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Headphones, top brands recommended are: Brand Rank 1: Tiamat Brand Rating: 4.43 Item_ID Rating 0 6853 4.66 1 3230 4.60 2 4708 4.51 3 7472 4.50 4 3557 4.43 _______________________________ ------------------------------- Brand Rank 2: ebasy Brand Rating: 4.4 Item_ID Rating 0 5521 4.54 1 2072 4.28 _______________________________ ------------------------------- Brand Rank 3: Bose Brand Rating: 4.21 Item_ID Rating 0 3432 4.62 1 2595 4.60 2 2469 4.57 3 1825 4.47 4 2480 4.46 _______________________________ ------------------------------- Brand Rank 4: TaoTronics Brand Rating: 4.2 Item_ID Rating 0 7721 4.71 1 6437 4.43 2 5812 4.42 3 4446 4.32 4 4922 4.28 _______________________________ ------------------------------- Brand Rank 5: Sony Brand Rating: 4.17 Item_ID Rating 0 6493 4.33 1 4959 4.24 2 3544 4.23 3 8196 4.23 4 3660 4.22 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Camera & Photo, top brands recommended are: Brand Rank 1: Fintie Brand Rating: 4.57 Item_ID Rating 0 4581 4.57 _______________________________ ------------------------------- Brand Rank 2: Savage Brand Rating: 4.56 Item_ID Rating 0 672 4.81 1 1564 4.71 2 1416 4.69 3 466 4.58 4 1375 4.57 _______________________________ ------------------------------- Brand Rank 3: Sony Brand Rating: 4.37 Item_ID Rating 0 2083 4.79 1 49 4.77 2 3738 4.75 3 1087 4.70 4 2657 4.65 _______________________________ ------------------------------- Brand Rank 4: Mpow Brand Rating: 4.36 Item_ID Rating 0 8004 4.36 _______________________________ ------------------------------- Brand Rank 5: Neewer Brand Rating: 4.33 Item_ID Rating 0 7443 4.57 1 7101 4.47 2 1605 4.45 3 3783 4.31 4 8341 4.16 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Accessories & Supplies, top brands recommended are: Brand Rank 1: Sennheiser Brand Rating: 4.6 Item_ID Rating 0 1560 4.69 1 227 4.41 2 4590 4.29 _______________________________ ------------------------------- Brand Rank 2: Etre Jeune Brand Rating: 4.49 Item_ID Rating 0 7827 4.67 1 3229 4.58 2 79 4.51 3 5081 4.49 4 1473 4.34 _______________________________ ------------------------------- Brand Rank 3: Fintie Brand Rating: 4.48 Item_ID Rating 0 3777 4.49 1 5806 4.48 _______________________________ ------------------------------- Brand Rank 4: ebasy Brand Rating: 4.4 Item_ID Rating 0 7163 4.87 1 1274 4.61 2 4036 4.58 3 4821 4.28 4 3576 4.26 _______________________________ ------------------------------- Brand Rank 5: EldHus Brand Rating: 4.21 Item_ID Rating 0 2106 4.75 1 5289 4.50 2 9188 4.49 3 8954 4.48 4 9169 4.46 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Television & Video, top brands recommended are: Brand Rank 1: Bose Brand Rating: 4.36 Item_ID Rating 0 5202 4.36 _______________________________ ------------------------------- Brand Rank 2: Panasonic Brand Rating: 4.33 Item_ID Rating 0 476 4.69 1 371 4.53 2 1618 4.43 3 1326 4.40 4 1563 4.21 _______________________________ ------------------------------- Brand Rank 3: Toshiba Brand Rating: 4.19 Item_ID Rating 0 4177 4.31 1 2214 4.09 2 2173 3.97 3 2984 3.89 _______________________________ ------------------------------- Brand Rank 4: Pyle Brand Rating: 4.12 Item_ID Rating 0 2454 4.25 1 1984 3.60 _______________________________ ------------------------------- Brand Rank 5: Samsung Brand Rating: 4.02 Item_ID Rating 0 2129 4.02 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Car Electronics & GPS, top brands recommended are: Brand Rank 1: JVC Brand Rating: 4.2 Item_ID Rating 0 1037 4.48 1 980 4.12 2 441 3.97 _______________________________ ------------------------------- Brand Rank 2: Garmin Brand Rating: 4.17 Item_ID Rating 0 1323 4.43 1 283 4.42 2 6625 4.16 3 1105 4.09 4 1668 4.08 _______________________________ ------------------------------- Brand Rank 3: Sony Brand Rating: 4.16 Item_ID Rating 0 2690 4.16 _______________________________ ------------------------------- Brand Rank 4: Mpow Brand Rating: 3.97 Item_ID Rating 0 5749 3.97 _______________________________ ------------------------------- Brand Rank 5: Uniden Brand Rating: 3.94 Item_ID Rating 0 1056 4.04 1 6731 3.17 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Home Audio, top brands recommended are: Brand Rank 1: EldHus Brand Rating: 4.51 Item_ID Rating 0 6662 4.51 _______________________________ ------------------------------- Brand Rank 2: Sony Brand Rating: 4.49 Item_ID Rating 0 511 4.49 _______________________________ ------------------------------- Brand Rank 3: TaoTronics Brand Rating: 4.17 Item_ID Rating 0 5054 4.17 1 8375 4.17 2 6328 4.16 _______________________________ ------------------------------- Brand Rank 4: Bose Brand Rating: 4.04 Item_ID Rating 0 211 4.47 1 3625 4.30 2 178 2.53 _______________________________ ------------------------------- Brand Rank 5: Pyle Brand Rating: 3.82 Item_ID Rating 0 1236 4.43 1 5096 4.27 2 5459 3.98 3 1205 3.96 4 827 3.89 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Security & Surveillance, top brands recommended are: Brand Rank 1: Uniden Brand Rating: 3.79 Item_ID Rating 0 3989 3.94 1 6638 3.75 2 1250 3.74 3 3603 3.19 _______________________________ ------------------------------- Brand Rank 2: Samsung Brand Rating: 3.75 Item_ID Rating 0 3293 3.75 _______________________________ ------------------------------- Brand Rank 3: Funlux Brand Rating: 3.16 Item_ID Rating 0 4831 3.16 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Wearable Technology, top brands recommended are: Brand Rank 1: Sony Brand Rating: 3.68 Item_ID Rating 0 5402 3.68 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Dresses, top brands recommended are: Brand Rank 1: Banned Brand Rating: 4.61 Item_ID Rating 0 145278 4.61 _______________________________ ------------------------------- Brand Rank 2: Ryu Brand Rating: 4.45 Item_ID Rating 0 110169 4.63 1 104356 4.56 2 48629 4.37 _______________________________ ------------------------------- Brand Rank 3: Pepaloves Brand Rating: 4.37 Item_ID Rating 0 153481 4.37 _______________________________ ------------------------------- Brand Rank 4: ModCloth Brand Rating: 4.3 Item_ID Rating 0 154064 4.78 1 70538 4.47 2 141105 4.34 3 137270 4.25 4 153445 4.25 _______________________________ ------------------------------- Brand Rank 5: Retrolicious Brand Rating: 4.3 Item_ID Rating 0 140020 4.51 1 28252 4.47 2 119314 4.46 3 40141 4.38 4 56780 4.32 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Outerwear, top brands recommended are: Brand Rank 1: Steve Madden Brand Rating: 4.43 Item_ID Rating 0 129113 4.51 1 27439 4.48 2 110824 4.28 3 110820 4.25 _______________________________ ------------------------------- Brand Rank 2: Jack by BB Dakota Brand Rating: 4.12 Item_ID Rating 0 71607 4.12 _______________________________ ------------------------------- Brand Rank 3: ModCloth Brand Rating: 4.07 Item_ID Rating 0 135555 4.61 1 123500 4.54 2 143136 4.34 3 85507 4.06 4 58990 3.93 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Bottoms, top brands recommended are: Brand Rank 1: Miss Candyfloss Brand Rating: 4.47 Item_ID Rating 0 133539 4.76 1 133399 4.44 2 121272 4.38 _______________________________ ------------------------------- Brand Rank 2: Pink Martini Brand Rating: 4.41 Item_ID Rating 0 111781 4.41 _______________________________ ------------------------------- Brand Rank 3: ModCloth Brand Rating: 4.27 Item_ID Rating 0 153454 4.62 1 141880 4.61 2 148257 4.61 3 153372 4.59 4 140727 4.59 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Tops, top brands recommended are: Brand Rank 1: Daisey Natives Brand Rating: 4.74 Item_ID Rating 0 143764 4.74 _______________________________ ------------------------------- Brand Rank 2: Kin Ship Brand Rating: 4.72 Item_ID Rating 0 70230 4.73 1 122266 4.72 _______________________________ ------------------------------- Brand Rank 3: Out of Print Brand Rating: 4.6 Item_ID Rating 0 67022 4.79 1 113643 4.25 _______________________________ ------------------------------- Brand Rank 4: ModCloth Brand Rating: 4.41 Item_ID Rating 0 153726 4.57 1 118020 4.53 2 40899 4.52 3 59176 4.51 4 126993 4.37 _______________________________ ------------------------------- Brand Rank 5: Banned Brand Rating: 3.9 Item_ID Rating 0 146244 3.9 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
def top_products_based_on_brand_2(category_name, brand_name):
"""This function prints dataframe of items and their ratings upon entering the category and brand"""
temp_df_2 = ovr_item_df[
(ovr_item_df.category == category_name) & (ovr_item_df.brand == brand_name)
].head()
item_list = temp_df_2.item_id.tolist()
rating_list = temp_df_2.rating.tolist()
return [f"{item_list[i]} - {rating_list[i]}" for i in range(len(item_list))]
brand_excel_df = pd.DataFrame(columns=["Recommendation_System_Type", "Category" ,"Brand","Brand_Rating", "Top_Products", "Sales"])
for k in range(14):
sol = top5_brands_rating(list_category[k])
for j in range(len(sol[1])):
brand_id = sol[1][j]
brand_rating = sol[2][j]
brand_excel_df.loc[len(brand_excel_df.index)] = ["Overall_Brandwise_Recommendation",list_category[k],brand_id,brand_rating,top_products_based_on_brand_2(list_category[k], brand_id), None]
def last2_item_suggestion(category_name):
"""this function gives list of top items, their respective brands and their ratings"""
temp_df3 = ovr_2_item_df[ovr_2_item_df.category == category_name].head()
return [
category_name,
temp_df3.item_id.tolist(),
temp_df3.brand.tolist(),
temp_df3.rating.tolist(),
]
print("Recommending Items based on their ratings received over the past 2 years:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for i in range(14):
item_list = last2_item_suggestion(list_category[i])
df = pd.DataFrame(
{"Product": item_list[1], "Brand": item_list[2], "Rating": item_list[3]}
)
print(f"For Category:{item_list[0]}")
print()
print(f"{df}")
print("_______________________________")
print()
print()
Recommending Items based on their ratings received over the past 2 years: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category:Portable Audio & Video Product Brand Rating 0 1064 Other 5.0 1 816 Uniden 5.0 2 790 Other 5.0 3 570 Archos 5.0 4 1149 Sony 5.0 _______________________________ For Category:Computers & Accessories Product Brand Rating 0 2939 Other 5.0 1 2958 Other 5.0 2 977 Apple 5.0 3 896 Other 5.0 4 7097 Other 5.0 _______________________________ For Category:Headphones Product Brand Rating 0 7222 Other 5.0 1 4320 Other 5.0 2 4458 Other 5.0 3 4140 Other 5.0 4 4568 Other 5.0 _______________________________ For Category:Camera & Photo Product Brand Rating 0 1598 ViewSonic 5.0 1 506 Other 5.0 2 6499 Other 5.0 3 520 Sony 5.0 4 537 Kodak 5.0 _______________________________ For Category:Accessories & Supplies Product Brand Rating 0 3960 Other 5.0 1 3661 Other 5.0 2 3719 Other 5.0 3 4112 Other 5.0 4 4469 Other 5.0 _______________________________ For Category:Television & Video Product Brand Rating 0 8122 Other 5.0 1 5030 Other 5.0 2 3656 Other 5.0 3 2606 Other 5.0 4 2214 Toshiba 5.0 _______________________________ For Category:Car Electronics & GPS Product Brand Rating 0 4465 Other 5.0 1 3300 Other 5.0 2 1521 Other 5.0 3 4476 Other 5.0 4 1401 Other 5.0 _______________________________ For Category:Home Audio Product Brand Rating 0 4481 Other 5.0 1 5636 Other 5.0 2 6198 Other 5.0 3 2655 Other 5.0 4 211 Bose 5.0 _______________________________ For Category:Security & Surveillance Product Brand Rating 0 1840 Other 5.00 1 5792 Other 4.54 2 3754 Other 4.42 3 2687 Other 4.33 4 4347 Other 4.29 _______________________________ For Category:Wearable Technology Product Brand Rating 0 4968 Other 4.50 1 8752 Other 4.29 2 2830 Other 4.26 3 6438 Other 4.10 4 8851 Other 4.02 _______________________________ For Category:Dresses Product Brand Rating 0 154064 ModCloth 4.78 1 146840 Other 4.72 2 61110 Chi Chi London 4.71 3 110169 Ryu 4.70 4 135791 Other 4.69 _______________________________ For Category:Outerwear Product Brand Rating 0 135555 ModCloth 4.60 1 123500 ModCloth 4.58 2 129113 Steve Madden 4.57 3 35272 Other 4.51 4 47325 Other 4.46 _______________________________ For Category:Bottoms Product Brand Rating 0 133539 Miss Candyfloss 4.83 1 102736 Other 4.81 2 70478 Other 4.71 3 114371 Other 4.69 4 137232 ModCloth 4.64 _______________________________ For Category:Tops Product Brand Rating 0 67022 Out of Print 4.81 1 122266 Kin Ship 4.78 2 63583 Other 4.73 3 137370 Other 4.73 4 143764 Daisey Natives 4.71 _______________________________
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
for i in range(14):
item_list = last2_item_suggestion(list_category[i])
df = pd.DataFrame(
{"Recommendation_System_Type":"Latest Trend Rating", "Category": item_list[0], "Product": item_list[1], "Brand": item_list[2], "Rating": item_list[3]}
)
items_excel_df = items_excel_df.append(df)
items_excel_df.to_csv("item_recommendation.csv")
"""Forming the required dataframe for past 2 years keeping category as the main parameter"""
last2_brand_df = (
past_2_years.groupby(by=["category", "brand"], as_index=False)
.agg({"rating": pd.Series.mean})
.sort_values(by="rating", ascending=False)
)
last2_brand_df = last2_brand_df[last2_brand_df.brand != "Other"]
last2_brand_df.rating = last2_brand_df.rating.round(2)
def brand_top_items_2years(category_name, brand_name):
"""this function prints the dataframe of Items and their ratings based upon category and brand"""
brand_items_2years = ovr_2_item_df[
(ovr_2_item_df.brand == brand_name) & (ovr_2_item_df.category == category_name)
].head()
brand_items = brand_items_2years.item_id.tolist()
brand_items_rating = brand_items_2years.rating.tolist()
df = pd.DataFrame({"Item_Code": brand_items, "Rating": brand_items_rating})
print(df)
def last2_brands_suggestion(category_name):
"""this function gives top brand names and their ratings"""
temp_df_1 = last2_brand_df[last2_brand_df.category == category_name].head()
top_brand_names = temp_df_1.brand.tolist()
top_brand_ratings = temp_df_1.rating.tolist()
return [top_brand_names, top_brand_ratings]
print("Recommending Items as per Top Brands:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for k in range(14):
print(f"For Category: {list_category[k]}, top brands recommended are:\n")
sol = last2_brands_suggestion(list_category[k])
for j in range(len(sol[0])):
brand_id = sol[0][j]
brand_rating = sol[1][j]
print(f"Brand Rank {j+1}: {brand_id}")
print(f"Brand Rating: {brand_rating}")
print()
brand_top_items_2years(list_category[k], brand_id)
print("_______________________________")
print("-------------------------------")
print()
print(
"________________________________________________________________________________________________"
)
print(
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)
print()
Recommending Items as per Top Brands: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category: Portable Audio & Video, top brands recommended are: Brand Rank 1: Mpow Brand Rating: 4.5 Item_Code Rating 0 5748 4.51 1 5974 3.33 _______________________________ ------------------------------- Brand Rank 2: Bose Brand Rating: 4.27 Item_Code Rating 0 7022 4.36 1 5171 3.99 2 3195 3.95 3 5156 3.86 4 7049 3.84 _______________________________ ------------------------------- Brand Rank 3: DBPOWER Brand Rating: 4.23 Item_Code Rating 0 4009 4.25 1 2864 4.00 2 4079 4.00 _______________________________ ------------------------------- Brand Rank 4: Sony Brand Rating: 4.14 Item_Code Rating 0 1149 5.00 1 1154 5.00 2 332 5.00 3 1764 5.00 4 1131 4.33 _______________________________ ------------------------------- Brand Rank 5: JLAB Brand Rating: 4.09 Item_Code Rating 0 2571 4.09 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Computers & Accessories, top brands recommended are: Brand Rank 1: Fujifilm Brand Rating: 5.0 Item_Code Rating 0 1432 5.0 _______________________________ ------------------------------- Brand Rank 2: Jabra Brand Rating: 4.73 Item_Code Rating 0 2253 4.80 1 1722 4.62 2 2903 4.15 _______________________________ ------------------------------- Brand Rank 3: Fintie Brand Rating: 4.61 Item_Code Rating 0 5245 5.00 1 5226 5.00 2 4696 5.00 3 4877 4.88 4 6123 4.80 _______________________________ ------------------------------- Brand Rank 4: Cooper Cases Brand Rating: 4.6 Item_Code Rating 0 8655 4.84 1 9089 4.58 2 9203 4.57 3 3818 4.27 _______________________________ ------------------------------- Brand Rank 5: Plemo Brand Rating: 4.43 Item_Code Rating 0 6839 4.51 1 3916 4.50 2 5989 4.45 3 3556 4.20 4 5168 3.00 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Headphones, top brands recommended are: Brand Rank 1: ebasy Brand Rating: 4.4 Item_Code Rating 0 5521 4.54 1 2072 4.30 _______________________________ ------------------------------- Brand Rank 2: Mpow Brand Rating: 4.16 Item_Code Rating 0 4019 5.00 1 6819 4.30 2 7809 4.08 3 6689 3.95 4 6835 3.86 _______________________________ ------------------------------- Brand Rank 3: Philips Brand Rating: 4.11 Item_Code Rating 0 547 5.00 1 1499 4.50 2 5257 4.48 3 1466 4.33 4 7526 4.26 _______________________________ ------------------------------- Brand Rank 4: Kensington Brand Rating: 4.07 Item_Code Rating 0 923 4.07 _______________________________ ------------------------------- Brand Rank 5: Bose Brand Rating: 4.01 Item_Code Rating 0 2469 5.00 1 1806 5.00 2 338 5.00 3 1447 5.00 4 1860 4.75 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Camera & Photo, top brands recommended are: Brand Rank 1: JVC Brand Rating: 4.8 Item_Code Rating 0 465 4.8 _______________________________ ------------------------------- Brand Rank 2: Fintie Brand Rating: 4.68 Item_Code Rating 0 4581 4.68 _______________________________ ------------------------------- Brand Rank 3: Sony Brand Rating: 4.63 Item_Code Rating 0 520 5.00 1 795 5.00 2 49 5.00 3 2491 5.00 4 2083 4.89 _______________________________ ------------------------------- Brand Rank 4: Canon Brand Rating: 4.59 Item_Code Rating 0 725 5.00 1 698 5.00 2 143 5.00 3 2979 5.00 4 9189 4.89 _______________________________ ------------------------------- Brand Rank 5: Savage Brand Rating: 4.43 Item_Code Rating 0 672 4.91 1 1564 4.68 2 2556 4.62 3 1375 4.62 4 1263 4.39 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Accessories & Supplies, top brands recommended are: Brand Rank 1: Fintie Brand Rating: 4.38 Item_Code Rating 0 3777 4.68 1 5806 4.25 _______________________________ ------------------------------- Brand Rank 2: Sennheiser Brand Rating: 4.38 Item_Code Rating 0 1560 4.65 1 4590 3.82 _______________________________ ------------------------------- Brand Rank 3: Pyle Brand Rating: 4.32 Item_Code Rating 0 4225 4.38 1 1744 4.11 2 5258 4.00 _______________________________ ------------------------------- Brand Rank 4: ebasy Brand Rating: 4.31 Item_Code Rating 0 3576 4.67 1 1274 4.50 2 4821 4.29 _______________________________ ------------------------------- Brand Rank 5: Etre Jeune Brand Rating: 4.26 Item_Code Rating 0 79 4.71 1 7827 4.55 2 8466 4.30 3 5081 4.24 4 1473 4.13 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Television & Video, top brands recommended are: Brand Rank 1: Panasonic Brand Rating: 4.42 Item_Code Rating 0 1618 5.00 1 1563 5.00 2 1326 5.00 3 1296 4.67 4 1604 2.50 _______________________________ ------------------------------- Brand Rank 2: Bose Brand Rating: 4.34 Item_Code Rating 0 5202 4.34 _______________________________ ------------------------------- Brand Rank 3: Pyle Brand Rating: 3.82 Item_Code Rating 0 1984 3.82 _______________________________ ------------------------------- Brand Rank 4: DBPOWER Brand Rating: 3.06 Item_Code Rating 0 8074 3.24 1 4633 2.50 2 2654 2.50 _______________________________ ------------------------------- Brand Rank 5: Samsung Brand Rating: 3.03 Item_Code Rating 0 2129 3.03 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Car Electronics & GPS, top brands recommended are: Brand Rank 1: JVC Brand Rating: 4.33 Item_Code Rating 0 1037 4.33 _______________________________ ------------------------------- Brand Rank 2: Uniden Brand Rating: 3.85 Item_Code Rating 0 1056 4.00 1 6731 2.75 _______________________________ ------------------------------- Brand Rank 3: Garmin Brand Rating: 3.78 Item_Code Rating 0 1323 4.60 1 283 4.35 2 6625 4.05 3 1105 3.99 4 7936 3.97 _______________________________ ------------------------------- Brand Rank 4: Pyle Brand Rating: 3.56 Item_Code Rating 0 593 3.95 1 2431 3.83 2 8335 3.75 3 638 3.56 4 8041 3.44 _______________________________ ------------------------------- Brand Rank 5: Mpow Brand Rating: 3.5 Item_Code Rating 0 5749 3.5 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Home Audio, top brands recommended are: Brand Rank 1: Sony Brand Rating: 4.54 Item_Code Rating 0 511 4.54 _______________________________ ------------------------------- Brand Rank 2: EldHus Brand Rating: 4.43 Item_Code Rating 0 6662 4.43 _______________________________ ------------------------------- Brand Rank 3: TaoTronics Brand Rating: 4.08 Item_Code Rating 0 8375 4.16 1 5054 4.02 2 6328 3.88 _______________________________ ------------------------------- Brand Rank 4: Pyle Brand Rating: 3.73 Item_Code Rating 0 2495 4.40 1 5096 4.37 2 827 4.22 3 1236 4.16 4 1205 4.06 _______________________________ ------------------------------- Brand Rank 5: Bose Brand Rating: 3.56 Item_Code Rating 0 211 5.0 1 3625 3.0 2 178 2.5 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Security & Surveillance, top brands recommended are: Brand Rank 1: Uniden Brand Rating: 3.66 Item_Code Rating 0 3989 3.71 1 1250 3.67 2 3603 3.50 3 6638 3.48 _______________________________ ------------------------------- Brand Rank 2: Samsung Brand Rating: 3.5 Item_Code Rating 0 3293 3.5 _______________________________ ------------------------------- Brand Rank 3: Funlux Brand Rating: 1.57 Item_Code Rating 0 4831 1.57 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Wearable Technology, top brands recommended are: Brand Rank 1: Sony Brand Rating: 3.66 Item_Code Rating 0 5402 3.66 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Dresses, top brands recommended are: Brand Rank 1: Banned Brand Rating: 4.61 Item_Code Rating 0 145278 4.61 _______________________________ ------------------------------- Brand Rank 2: Ryu Brand Rating: 4.55 Item_Code Rating 0 110169 4.70 1 104356 4.54 2 48629 4.50 _______________________________ ------------------------------- Brand Rank 3: Retrolicious Brand Rating: 4.38 Item_Code Rating 0 140020 4.65 1 28252 4.47 2 119314 4.40 3 40141 4.38 4 56780 4.29 _______________________________ ------------------------------- Brand Rank 4: Pepaloves Brand Rating: 4.37 Item_Code Rating 0 153481 4.37 _______________________________ ------------------------------- Brand Rank 5: Chi Chi London Brand Rating: 4.2 Item_Code Rating 0 61110 4.71 1 129160 4.41 2 107539 4.39 3 141853 4.29 4 135364 4.25 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Outerwear, top brands recommended are: Brand Rank 1: Steve Madden Brand Rating: 4.22 Item_Code Rating 0 129113 4.57 1 27439 4.25 2 110820 4.16 3 110824 3.54 _______________________________ ------------------------------- Brand Rank 2: ModCloth Brand Rating: 4.22 Item_Code Rating 0 135555 4.60 1 123500 4.58 2 143136 4.34 3 78510 4.12 4 56289 4.12 _______________________________ ------------------------------- Brand Rank 3: Jack by BB Dakota Brand Rating: 4.02 Item_Code Rating 0 71607 4.02 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Bottoms, top brands recommended are: Brand Rank 1: Pink Martini Brand Rating: 4.46 Item_Code Rating 0 111781 4.46 _______________________________ ------------------------------- Brand Rank 2: Miss Candyfloss Brand Rating: 4.42 Item_Code Rating 0 133539 4.83 1 133399 4.40 2 121272 4.25 _______________________________ ------------------------------- Brand Rank 3: ModCloth Brand Rating: 4.38 Item_Code Rating 0 137232 4.64 1 153454 4.62 2 141880 4.62 3 148257 4.61 4 153372 4.59 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Tops, top brands recommended are: Brand Rank 1: Kin Ship Brand Rating: 4.76 Item_Code Rating 0 122266 4.78 1 70230 4.67 _______________________________ ------------------------------- Brand Rank 2: Daisey Natives Brand Rating: 4.71 Item_Code Rating 0 143764 4.71 _______________________________ ------------------------------- Brand Rank 3: Out of Print Brand Rating: 4.58 Item_Code Rating 0 67022 4.81 1 113643 4.00 _______________________________ ------------------------------- Brand Rank 4: ModCloth Brand Rating: 4.3 Item_Code Rating 0 40899 4.63 1 59176 4.57 2 153726 4.57 3 118020 4.51 4 126993 4.40 _______________________________ ------------------------------- Brand Rank 5: Banned Brand Rating: 4.02 Item_Code Rating 0 146244 4.02 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
def brand_top_items_2years_2(category_name, brand_name):
"""this function prints the dataframe of Items and their ratings based upon category and brand"""
brand_items_2years = ovr_2_item_df[
(ovr_2_item_df.brand == brand_name) & (ovr_2_item_df.category == category_name)
].head()
brand_items = brand_items_2years.item_id.tolist()
brand_items_rating = brand_items_2years.rating.tolist()
return [f"{brand_items[i]} - {brand_items_rating[i]}" for i in range(len(brand_items))]
# brand_excel_df = pd.DataFrame(columns=["Recommendation_System_Type", "Category" ,"Brand","Brand_Rating", "Top_Products", "Sales"])
for k in range(14):
sol = last2_brands_suggestion(list_category[k])
for j in range(len(sol[0])):
brand_id = sol[0][j]
brand_rating = sol[1][j]
brand_excel_df.loc[len(brand_excel_df.index)] = ["Latest_Brandwise_Recommendation",list_category[k],brand_id,brand_rating,brand_top_items_2years_2(list_category[k], brand_id), None]
brand_excel_df.to_csv("brand_recommendation.csv")
"""For Collaborative Filtering Recommendation System, we also consider the Users.
Hence, we will consider only those items rated by user who has also reviewed at least one more item
(i.e. we will remove all users who have bought only 1 item)"""
"""let us form DataFrame of Users and the items they have purchased"""
rough = consolidated_db2["user_id"].value_counts().sort_values()
user_purchases = pd.DataFrame({"user_id": rough.index, "items_bought": rough.values})
# For demonstration purposes
user_purchases.tail()
| user_id | items_bought | |
|---|---|---|
| 1112962 | Jennifer | 154 |
| 1112963 | Amanda | 158 |
| 1112964 | Jessica | 159 |
| 1112965 | Laura | 160 |
| 1112966 | Sarah | 187 |
"""Let us form DataFrame of users who have bought more than 1 item"""
collab_df = consolidated_db2.copy()
collab_df = pd.merge(collab_df, user_purchases, on="user_id")
collab_df = collab_df[collab_df.items_bought > 1]
"""We will consider only relevant columns required for Collaborative Filtering in our DataFrame"""
collab_df = collab_df[["item_id", "user_id", "rating", "category"]]
collab_df.head()
| item_id | user_id | rating | category | |
|---|---|---|---|---|
| 7 | 0 | 7 | 2.0 | Portable Audio & Video |
| 8 | 2205 | 7 | 5.0 | Computers & Accessories |
| 9 | 9046 | 7 | 5.0 | Accessories & Supplies |
| 28 | 0 | 28 | 2.0 | Portable Audio & Video |
| 29 | 651 | 28 | 4.0 | Camera & Photo |
"""create pivot table"""
collab_df_pivot = collab_df.pivot(
index="item_id", columns="user_id", values="rating"
).fillna(0)
"""create sparse matrix to pass to KNN model for training"""
features_df_matrix = csr_matrix(collab_df_pivot.values)
"""creating list of modcloth item_ids"""
item_list = collab_df_pivot.index.tolist()
"""creating KNN model"""
model_knn = NearestNeighbors(metric="cosine", algorithm="brute")
"""fitting the model"""
model_knn.fit(features_df_matrix)
"""Let us build a function which gives 5 nearest neighbours of item"""
def recommender_whole(item_id):
query_index = np.random.choice(collab_df_pivot.shape[0])
distances, indices = model_knn.kneighbors(
collab_df_pivot[collab_df_pivot.index == item_id].values.reshape(1, -1),
n_neighbors=6,
)
nearest_items = [collab_df_pivot.index[i] for i in indices.flatten()[1:]]
nearest_items_category = [
item_category[item_category.item_id == item]["category"].values[0]
for item in nearest_items
]
recommended_items_df = pd.DataFrame(
{"Recommended_Item": nearest_items, "Category": nearest_items_category}
)
return recommended_items_df
for item in [np.random.choice(collab_df_pivot.index) for i in range(5)]:
print()
cat = item_category[item_category.item_id == 0]["category"].values[0]
print(
f"For Item_ID: {item} belonging to Category: {cat}, the top 5 items recommended are:"
)
print()
print(recommender_whole(item))
print()
print(
"_____________________________________________________________________________________________"
)
print(
"============================================================================================="
)
For Item_ID: 2037 belonging to Category: Portable Audio & Video, the top 5 items recommended are: Recommended_Item Category 0 2157 Headphones 1 5759 Headphones 2 6276 Computers & Accessories 3 3744 Accessories & Supplies 4 8072 Camera & Photo _____________________________________________________________________________________________ ============================================================================================= For Item_ID: 2221 belonging to Category: Portable Audio & Video, the top 5 items recommended are: Recommended_Item Category 0 874 Camera & Photo 1 6372 Computers & Accessories 2 4040 Camera & Photo 3 9142 Headphones 4 5288 Computers & Accessories _____________________________________________________________________________________________ ============================================================================================= For Item_ID: 3772 belonging to Category: Portable Audio & Video, the top 5 items recommended are: Recommended_Item Category 0 4319 Portable Audio & Video 1 4385 Camera & Photo 2 4401 Headphones 3 167 Camera & Photo 4 3570 Headphones _____________________________________________________________________________________________ ============================================================================================= For Item_ID: 5009 belonging to Category: Portable Audio & Video, the top 5 items recommended are: Recommended_Item Category 0 7590 Headphones 1 5749 Car Electronics & GPS 2 2857 Headphones 3 3230 Headphones 4 9415 Headphones _____________________________________________________________________________________________ ============================================================================================= For Item_ID: 5746 belonging to Category: Portable Audio & Video, the top 5 items recommended are: Recommended_Item Category 0 2502 Computers & Accessories 1 6797 Headphones 2 6254 Camera & Photo 3 5691 Headphones 4 7494 Headphones _____________________________________________________________________________________________ =============================================================================================
best_selling_db = consolidated_db2[
["item_id", "timestamp", "category", "brand", "count"]
]
"""itemwise dataframe"""
best_selling_item = (
best_selling_db.groupby(by=["item_id", "category", "brand"], as_index=False)
.agg({"count": pd.Series.sum})
.sort_values(by="count", ascending=False)
)
def top5_bestselling_items_over(category_name):
"""this function prints the dataframe which shows Items, their respective brand and units sold for category entered"""
df = best_selling_item[best_selling_item.category == category_name].head()
item_list = df.item_id.tolist()
brand_list = df.brand.tolist()
sold_list = df["count"].tolist()
temp_df = pd.DataFrame(
{"Item_ID": item_list, "Brand": brand_list, "Sold_Units": sold_list}
)
print(temp_df)
"""brandwise dataframe"""
"""For suggesting brand, we cannot suggest "Other" as brand as we have substitued "Other" for Missing values.
Hence, we will drop "Other" brand and consider the rest"""
best_selling_brand_raw = best_selling_db[best_selling_db.brand != "Other"]
"""Forming DataFrame"""
best_selling_brand = (
best_selling_brand_raw.groupby(by=["category", "brand"], as_index=False)
.agg({"count": pd.Series.sum})
.sort_values(by="count", ascending=False)
)
def best_selling_brand_ovr(category):
"""this function returns list of top brands and the units sold for the respective brands"""
temp_df = best_selling_brand[best_selling_brand.category == category].head()
brand_list = temp_df.brand.tolist()
sold_list = temp_df["count"].tolist()
return [brand_list, sold_list]
def bestselling_brand_items_ovr(category_name, brand_name):
"""this function prints the dataframe showing items and the respective units sold for those items for a given category"""
temp_df = best_selling_item[
(best_selling_item.brand == brand_name)
& (best_selling_item.category == category_name)
].head()
item_list = temp_df.item_id.tolist()
sold_list = temp_df["count"].tolist()
df = pd.DataFrame({"Item_ID": item_list, "Units Sold": sold_list})
print(df)
print("Best Selling Items from 1999 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for i in range(len(list_category)):
print(f"For Category:{list_category[i]}")
print()
top5_bestselling_items_over(list_category[i])
print("_______________________________")
print()
print()
Best Selling Items from 1999 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category:Portable Audio & Video Item_ID Brand Sold_Units 0 7780 Other 28530 1 5063 Other 3875 2 5940 Other 3437 3 4009 DBPOWER 3340 4 7022 Bose 3183 _______________________________ For Category:Computers & Accessories Item_ID Brand Sold_Units 0 2031 Logitech 9393 1 2279 Other 6278 2 2486 Other 5810 3 1124 Logitech 5353 4 647 Logitech 4520 _______________________________ For Category:Headphones Item_ID Brand Sold_Units 0 1575 Sony 8622 1 2340 Other 5790 2 5795 Other 5554 3 1886 Other 5323 4 6210 Other 4916 _______________________________ For Category:Camera & Photo Item_ID Brand Sold_Units 0 5897 Other 3824 1 2237 Other 3777 2 1605 Neewer 3677 3 1875 Other 2636 4 6726 Polaroid 2086 _______________________________ For Category:Accessories & Supplies Item_ID Brand Sold_Units 0 1715 Other 5482 1 2483 Other 4325 2 6818 Other 4105 3 3995 Other 3716 4 791 Other 3316 _______________________________ For Category:Television & Video Item_ID Brand Sold_Units 0 2129 Samsung 4022 1 3617 Other 2420 2 4495 Other 1915 3 1735 Other 1252 4 6358 Other 991 _______________________________ For Category:Car Electronics & GPS Item_ID Brand Sold_Units 0 3728 Other 4345 1 6005 Other 2864 2 283 Garmin 2863 3 1105 Garmin 1457 4 5838 Other 938 _______________________________ For Category:Home Audio Item_ID Brand Sold_Units 0 5054 TaoTronics 4033 1 8375 TaoTronics 1252 2 3303 Other 1025 3 6328 TaoTronics 931 4 8802 Other 918 _______________________________ For Category:Security & Surveillance Item_ID Brand Sold_Units 0 9127 Other 994 1 6427 Other 572 2 7697 Other 536 3 3989 Uniden 529 4 3013 Other 523 _______________________________ For Category:Wearable Technology Item_ID Brand Sold_Units 0 2957 Other 3935 1 4968 Other 1300 2 7251 Other 1081 3 8851 Other 690 4 5402 Sony 637 _______________________________ For Category:Dresses Item_ID Brand Sold_Units 0 32405 Other 1599 1 32406 Other 1494 2 32403 Other 1378 3 16411 Other 1260 4 55967 Other 1164 _______________________________ For Category:Outerwear Item_ID Brand Sold_Units 0 11960 Other 854 1 27439 Steve Madden 772 2 32236 Other 751 3 35272 Other 561 4 58990 ModCloth 418 _______________________________ For Category:Bottoms Item_ID Brand Sold_Units 0 21296 ModCloth 1636 1 50818 Other 998 2 62447 Other 998 3 80238 Other 925 4 54222 ModCloth 749 _______________________________ For Category:Tops Item_ID Brand Sold_Units 0 34935 Other 1887 1 67507 Other 1357 2 57369 Other 1133 3 40899 ModCloth 957 4 59176 ModCloth 933 _______________________________
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# def top5_bestselling_items_over_1(category_name):
# """this function prints the dataframe which shows Items, their respective brand and units sold for category entered"""
# df = best_selling_item[best_selling_item.category == category_name].head()
# item_list = df.item_id.tolist()
# brand_list = df.brand.tolist()
# sold_list = df["count"].tolist()
# temp_df = pd.DataFrame(
# {"Item_ID": item_list, "Brand": brand_list, "Sold_Units": sold_list}
# )
# return temp_df
# temp_df2 = pd.DataFrame(columns=["Category", "Item_ID", "Brand", "Sold_Units"])
# for i in range(len(list_category)):
# # print(f"For Category:{list_category[i]}")
# temp_df = top5_bestselling_items_over_1(list_category[i])
# temp_df.insert(0,"Category",list_category[i])
# temp_df2 = temp_df2.append(temp_df)
# temp_df2.insert(0,"Recommendation_Type","Overall_Bestselling_Items")
# bestselling_item_recommendation = temp_df2.copy()
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
print("Recommending Items as per Top Selling Brand from 1999 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for k in range(len(list_category)):
print(f"For Category: {list_category[k]}, best selling brands recommended are:\n")
sol = best_selling_brand_ovr(list_category[k])
for j in range(len(sol[0])):
brand_id = sol[0][j]
brand_rating = sol[1][j]
print(f"Brand Number {j+1}: {brand_id}")
print(f"Brand Units Sold: {brand_rating}")
print()
bestselling_brand_items_ovr(list_category[k], brand_id)
print("_______________________________")
print("-------------------------------")
print()
print(
"________________________________________________________________________________________________"
)
print(
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)
print()
Recommending Items as per Top Selling Brand from 1999 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category: Portable Audio & Video, best selling brands recommended are: Brand Number 1: Bose Brand Units Sold: 6826 Item_ID Units Sold 0 7022 3183 1 5171 1151 2 5273 1147 3 5156 630 4 3195 550 _______________________________ ------------------------------- Brand Number 2: DBPOWER Brand Units Sold: 3812 Item_ID Units Sold 0 4009 3340 1 2864 385 2 4079 87 _______________________________ ------------------------------- Brand Number 3: Pyle Brand Units Sold: 3083 Item_ID Units Sold 0 33 567 1 3468 293 2 4753 257 3 5445 244 4 3502 235 _______________________________ ------------------------------- Brand Number 4: Uniden Brand Units Sold: 2802 Item_ID Units Sold 0 2223 806 1 2159 753 2 2434 275 3 4419 224 4 1848 199 _______________________________ ------------------------------- Brand Number 5: Mpow Brand Units Sold: 1807 Item_ID Units Sold 0 5748 1754 1 5974 53 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Computers & Accessories, best selling brands recommended are: Brand Number 1: Logitech Brand Units Sold: 28699 Item_ID Units Sold 0 2031 9393 1 1124 5353 2 647 4520 3 1780 2711 4 1661 1387 _______________________________ ------------------------------- Brand Number 2: Linksys Brand Units Sold: 7885 Item_ID Units Sold 0 710 1191 1 1055 866 2 679 847 3 142 731 4 1367 594 _______________________________ ------------------------------- Brand Number 3: Fintie Brand Units Sold: 4348 Item_ID Units Sold 0 8736 1389 1 5354 413 2 3643 371 3 4696 183 4 2983 177 _______________________________ ------------------------------- Brand Number 4: Apple Brand Units Sold: 4281 Item_ID Units Sold 0 5405 1020 1 4302 834 2 5364 737 3 6562 457 4 5329 404 _______________________________ ------------------------------- Brand Number 5: Bose Brand Units Sold: 2999 Item_ID Units Sold 0 3106 2999 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Headphones, best selling brands recommended are: Brand Number 1: Bose Brand Units Sold: 18227 Item_ID Units Sold 0 5041 3452 1 1670 2969 2 4969 1675 3 7828 1532 4 7869 1336 _______________________________ ------------------------------- Brand Number 2: Mpow Brand Units Sold: 14819 Item_ID Units Sold 0 6819 4058 1 6689 3967 2 5009 1523 3 7356 1026 4 6687 961 _______________________________ ------------------------------- Brand Number 3: Sennheiser Brand Units Sold: 11406 Item_ID Units Sold 0 162 4002 1 259 3299 2 1242 964 3 554 555 4 1911 414 _______________________________ ------------------------------- Brand Number 4: Sony Brand Units Sold: 11213 Item_ID Units Sold 0 1575 8622 1 3092 499 2 2450 296 3 7202 285 4 3480 258 _______________________________ ------------------------------- Brand Number 5: Skullcandy Brand Units Sold: 9804 Item_ID Units Sold 0 2355 3347 1 5178 2366 2 8195 1222 3 3524 849 4 8350 471 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Camera & Photo, best selling brands recommended are: Brand Number 1: Fujifilm Brand Units Sold: 10882 Item_ID Units Sold 0 1258 1773 1 17 1073 2 3384 935 3 4407 744 4 751 660 _______________________________ ------------------------------- Brand Number 2: Kodak Brand Units Sold: 7620 Item_ID Units Sold 0 1423 1352 1 1119 842 2 1289 589 3 1690 411 4 217 208 _______________________________ ------------------------------- Brand Number 3: Neewer Brand Units Sold: 6261 Item_ID Units Sold 0 1605 3677 1 8341 1202 2 8077 481 3 5209 237 4 3783 185 _______________________________ ------------------------------- Brand Number 4: Nikon Brand Units Sold: 6036 Item_ID Units Sold 0 1307 665 1 1156 484 2 296 452 3 1304 425 4 1282 381 _______________________________ ------------------------------- Brand Number 5: Canon Brand Units Sold: 5849 Item_ID Units Sold 0 1593 1025 1 220 724 2 2881 604 3 3364 340 4 6434 279 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Accessories & Supplies, best selling brands recommended are: Brand Number 1: EldHus Brand Units Sold: 8113 Item_ID Units Sold 0 1861 1448 1 3539 1187 2 927 1185 3 1210 723 4 8282 661 _______________________________ ------------------------------- Brand Number 2: Etre Jeune Brand Units Sold: 4398 Item_ID Units Sold 0 7827 981 1 3229 929 2 1473 909 3 79 661 4 5081 486 _______________________________ ------------------------------- Brand Number 3: Jabra Brand Units Sold: 2090 Item_ID Units Sold 0 1750 1284 1 4811 588 2 3049 153 3 2243 65 _______________________________ ------------------------------- Brand Number 4: ebasy Brand Units Sold: 1098 Item_ID Units Sold 0 4821 461 1 3576 256 2 1274 217 3 4036 95 4 7163 69 _______________________________ ------------------------------- Brand Number 5: Sennheiser Brand Units Sold: 745 Item_ID Units Sold 0 1560 569 1 4590 122 2 227 54 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Television & Video, best selling brands recommended are: Brand Number 1: Samsung Brand Units Sold: 4022 Item_ID Units Sold 0 2129 4022 _______________________________ ------------------------------- Brand Number 2: Panasonic Brand Units Sold: 1074 Item_ID Units Sold 0 1618 287 1 1296 228 2 476 189 3 1604 129 4 1563 109 _______________________________ ------------------------------- Brand Number 3: Toshiba Brand Units Sold: 790 Item_ID Units Sold 0 4177 497 1 2173 155 2 2984 72 3 2214 66 _______________________________ ------------------------------- Brand Number 4: DBPOWER Brand Units Sold: 456 Item_ID Units Sold 0 8074 296 1 4633 108 2 2654 52 _______________________________ ------------------------------- Brand Number 5: Bose Brand Units Sold: 441 Item_ID Units Sold 0 5202 441 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Car Electronics & GPS, best selling brands recommended are: Brand Number 1: Garmin Brand Units Sold: 7054 Item_ID Units Sold 0 283 2863 1 1105 1457 2 4152 676 3 1323 421 4 7936 319 _______________________________ ------------------------------- Brand Number 2: Pyle Brand Units Sold: 1259 Item_ID Units Sold 0 638 587 1 8041 126 2 8335 108 3 6858 105 4 593 103 _______________________________ ------------------------------- Brand Number 3: Uniden Brand Units Sold: 638 Item_ID Units Sold 0 1056 567 1 6731 71 _______________________________ ------------------------------- Brand Number 4: Mpow Brand Units Sold: 504 Item_ID Units Sold 0 5749 504 _______________________________ ------------------------------- Brand Number 5: JVC Brand Units Sold: 220 Item_ID Units Sold 0 1037 77 1 980 73 2 441 70 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Home Audio, best selling brands recommended are: Brand Number 1: TaoTronics Brand Units Sold: 6216 Item_ID Units Sold 0 5054 4033 1 8375 1252 2 6328 931 _______________________________ ------------------------------- Brand Number 2: Pyle Brand Units Sold: 3558 Item_ID Units Sold 0 827 743 1 1236 618 2 1125 600 3 3090 433 4 1013 432 _______________________________ ------------------------------- Brand Number 3: Sony Brand Units Sold: 554 Item_ID Units Sold 0 511 554 _______________________________ ------------------------------- Brand Number 4: Bose Brand Units Sold: 431 Item_ID Units Sold 0 3625 192 1 211 161 2 178 78 _______________________________ ------------------------------- Brand Number 5: EldHus Brand Units Sold: 204 Item_ID Units Sold 0 6662 204 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Security & Surveillance, best selling brands recommended are: Brand Number 1: Uniden Brand Units Sold: 1018 Item_ID Units Sold 0 3989 529 1 1250 276 2 3603 111 3 6638 102 _______________________________ ------------------------------- Brand Number 2: Funlux Brand Units Sold: 81 Item_ID Units Sold 0 4831 81 _______________________________ ------------------------------- Brand Number 3: Samsung Brand Units Sold: 57 Item_ID Units Sold 0 3293 57 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Wearable Technology, best selling brands recommended are: Brand Number 1: Sony Brand Units Sold: 637 Item_ID Units Sold 0 5402 637 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Dresses, best selling brands recommended are: Brand Number 1: Chi Chi London Brand Units Sold: 2851 Item_ID Units Sold 0 107539 975 1 61110 369 2 126114 331 3 126098 171 4 135364 153 _______________________________ ------------------------------- Brand Number 2: Retrolicious Brand Units Sold: 1904 Item_ID Units Sold 0 56780 621 1 28252 616 2 35525 310 3 119314 182 4 40141 105 _______________________________ ------------------------------- Brand Number 3: ModCloth Brand Units Sold: 1797 Item_ID Units Sold 0 70538 1045 1 142002 120 2 137270 106 3 154064 85 4 150866 71 _______________________________ ------------------------------- Brand Number 4: Ryu Brand Units Sold: 576 Item_ID Units Sold 0 48629 352 1 104356 143 2 110169 81 _______________________________ ------------------------------- Brand Number 5: Emily and Fin Brand Units Sold: 384 Item_ID Units Sold 0 128563 210 1 153665 92 2 141295 82 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Outerwear, best selling brands recommended are: Brand Number 1: ModCloth Brand Units Sold: 1381 Item_ID Units Sold 0 58990 418 1 56289 208 2 78510 193 3 85507 192 4 123500 147 _______________________________ ------------------------------- Brand Number 2: Steve Madden Brand Units Sold: 1172 Item_ID Units Sold 0 27439 772 1 110820 195 2 110824 116 3 129113 89 _______________________________ ------------------------------- Brand Number 3: Jack by BB Dakota Brand Units Sold: 330 Item_ID Units Sold 0 71607 330 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Bottoms, best selling brands recommended are: Brand Number 1: ModCloth Brand Units Sold: 4111 Item_ID Units Sold 0 21296 1636 1 54222 749 2 121554 214 3 141880 168 4 153501 139 _______________________________ ------------------------------- Brand Number 2: Miss Candyfloss Brand Units Sold: 307 Item_ID Units Sold 0 121272 148 1 133399 100 2 133539 59 _______________________________ ------------------------------- Brand Number 3: Pink Martini Brand Units Sold: 68 Item_ID Units Sold 0 111781 68 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Tops, best selling brands recommended are: Brand Number 1: ModCloth Brand Units Sold: 3271 Item_ID Units Sold 0 40899 957 1 59176 933 2 118020 382 3 118948 169 4 112771 168 _______________________________ ------------------------------- Brand Number 2: Out of Print Brand Units Sold: 696 Item_ID Units Sold 0 67022 448 1 113643 248 _______________________________ ------------------------------- Brand Number 3: Kin Ship Brand Units Sold: 360 Item_ID Units Sold 0 122266 192 1 70230 168 _______________________________ ------------------------------- Brand Number 4: Banned Brand Units Sold: 93 Item_ID Units Sold 0 146244 93 _______________________________ ------------------------------- Brand Number 5: Daisey Natives Brand Units Sold: 58 Item_ID Units Sold 0 143764 58 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# def bestselling_brand_items_ovr_1(category_name, brand_name):
# """this function prints the dataframe showing items and the respective units sold for those items for a given category"""
# temp_df = best_selling_item[
# (best_selling_item.brand == brand_name)
# & (best_selling_item.category == category_name)
# ].head()
# item_list = temp_df.item_id.tolist()
# return item_list
# bestselling_brand_recommendation = pd.DataFrame(
# columns=[
# "Recommendation_System_Type",
# "Category",
# "Brand",
# "Brand_Sales",
# "Top_Products",
# ]
# )
# for k in range(len(list_category)):
# # print(f"For Category: {list_category[k]}, best selling brands recommended are:\n")
# sol = best_selling_brand_ovr(list_category[k])
# for j in range(len(sol[0])):
# brand_id = sol[0][j]
# brand_rating = sol[1][j]
# # print(f"Brand Number {j+1}: {brand_id}")
# # print(f"Brand Rating: {brand_rating}")
# item_list_1 = bestselling_brand_items_ovr_1(list_category[k], brand_id)
# bestselling_brand_recommendation.loc[len(bestselling_brand_recommendation)] = [
# "Overall_Bestselling_Brand",
# list_category[k],
# brand_id,
# brand_rating,
# item_list_1
# ]
# # bestselling_brand_recommendation
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
"""Forming the dataframe of past 2 years"""
best_selling_2years = best_selling_db[best_selling_db.timestamp > "2017-01-01"]
"""itemwise"""
best_selling_item_2years = (
best_selling_2years.groupby(by=["item_id", "category", "brand"], as_index=False)
.agg({"count": pd.Series.sum})
.sort_values(by="count", ascending=False)
)
def top5_bestselling_items_2years(category_name):
"""this function prints dataframe showing items, their respective brands & respective units sold for given category"""
df = best_selling_item_2years[best_selling_item.category == category_name].head()
item_list = df.item_id.tolist()
brand_list = df.brand.tolist()
sold_list = df["count"].tolist()
temp_df = pd.DataFrame(
{"Item_ID": item_list, "Brand": brand_list, "Sold_Units": sold_list}
)
print(temp_df)
"""brandwise"""
"""For suggesting brand, we cannot suggest "Other" as brand as we have substitued "Other" for Missing values.
Hence, we will drop "Other" brand and consider the rest"""
best_selling_brand_raw_2years = best_selling_2years[best_selling_db.brand != "Other"]
"""Forming DataFrame"""
best_selling_brand_2years = (
best_selling_brand_raw_2years.groupby(by=["category", "brand"], as_index=False)
.agg({"count": pd.Series.sum})
.sort_values(by="count", ascending=False)
)
<ipython-input-78-afde63db66b6>:5: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
def best_selling_brand_2years_fun(category_name):
"""this function returns list of best selling brands and the units sold for a given category"""
temp_df = best_selling_brand_2years[
best_selling_brand_2years.category == category_name
].head()
brand_list = temp_df.brand.tolist()
sold_list = temp_df["count"].tolist()
return [brand_list, sold_list]
def bestselling_brand_items_2years(category_name, brand_name):
"""this function prints dataframe showing best-selling items & units sold for given category and brand"""
temp_df = best_selling_item_2years[
(best_selling_item_2years.brand == brand_name)
& (best_selling_item_2years.category == category_name)
].head()
item_list = temp_df.item_id.tolist()
sold_list = temp_df["count"].tolist()
df = pd.DataFrame({"Item_ID": item_list, "Units Sold": sold_list})
print(df)
print("Recent Trends: Best Selling Items from 2017 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for i in range(len(list_category)):
print(f"For Category:{list_category[i]}")
print()
top5_bestselling_items_2years(list_category[i])
print("_______________________________")
print()
print()
Recent Trends: Best Selling Items from 2017 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category:Portable Audio & Video Item_ID Brand Sold_Units 0 2031 Logitech 3042 1 7022 Bose 2043 2 2237 Other 1881 3 5897 Other 1735 4 647 Logitech 1170 _______________________________ For Category:Computers & Accessories Item_ID Brand Sold_Units 0 6819 Mpow 3734 1 5063 Other 3312 2 4009 DBPOWER 2772 3 6689 Mpow 1592 4 5041 Bose 1190 _______________________________ For Category:Headphones Item_ID Brand Sold_Units 0 6378 Other 3234 1 6210 Other 2873 2 5795 Other 2281 3 5884 Other 1856 4 6818 Other 1818 _______________________________ For Category:Camera & Photo Item_ID Brand Sold_Units 0 162 Sennheiser 2575 1 5054 TaoTronics 1388 2 274 Other 1346 3 5301 Other 1151 4 6535 Other 1106 _______________________________ For Category:Accessories & Supplies Item_ID Brand Sold_Units 0 7780 Other 15639 1 1034 Other 1319 2 1706 Other 1064 3 3106 Bose 980 4 5548 Other 919 _______________________________ For Category:Television & Video Item_ID Brand Sold_Units 0 8802 Other 489 1 7730 Other 449 2 1575 Sony 374 3 6036 Other 330 4 7291 Other 211 _______________________________ For Category:Car Electronics & GPS Item_ID Brand Sold_Units 0 7770 Other 1033 1 3930 Other 506 2 3649 Other 414 3 8851 Other 394 4 7107 Other 384 _______________________________ For Category:Home Audio Item_ID Brand Sold_Units 0 7206 Other 2068 1 2793 Other 382 2 2837 Other 257 3 6396 Generic 187 4 1211 Other 182 _______________________________ For Category:Security & Surveillance Item_ID Brand Sold_Units 0 6170 Other 3214 1 3201 Other 363 2 7055 Other 279 3 2678 Other 266 4 6744 Other 235 _______________________________ For Category:Wearable Technology Item_ID Brand Sold_Units 0 4718 Other 1665 1 4969 Bose 812 2 5914 Other 196 3 4834 Other 170 4 5808 Other 166 _______________________________ For Category:Dresses Item_ID Brand Sold_Units 0 8436 Other 27 1 7341 Other 5 _______________________________ For Category:Outerwear Empty DataFrame Columns: [Item_ID, Brand, Sold_Units] Index: [] _______________________________ For Category:Bottoms Empty DataFrame Columns: [Item_ID, Brand, Sold_Units] Index: [] _______________________________ For Category:Tops Empty DataFrame Columns: [Item_ID, Brand, Sold_Units] Index: [] _______________________________
<ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index. <ipython-input-77-cb13e6549788>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# def top5_bestselling_items_2years_1(category_name):
# """this function prints dataframe showing items, their respective brands & respective units sold for given category"""
# df = best_selling_item_2years[best_selling_item.category == category_name].head()
# item_list = df.item_id.tolist()
# brand_list = df.brand.tolist()
# sold_list = df["count"].tolist()
# temp_df = pd.DataFrame(
# {"Item_ID": item_list, "Brand": brand_list, "Sold_Units": sold_list}
# )
# return temp_df
# temp_df3 = pd.DataFrame(columns=["Category", "Item_ID", "Brand", "Sold_Units"])
# for i in range(len(list_category)):
# # print(f"For Category:{list_category[i]}")
# temp_df = top5_bestselling_items_over_1(list_category[i])
# temp_df.insert(0,"Category",list_category[i])
# temp_df3 = temp_df3.append(temp_df)
# temp_df3.insert(0,"Recommendation_Type","Latest_Bestselling_Items")
# bestselling_item_recommendation = bestselling_item_recommendation.append(temp_df3.copy())
# bestselling_item_recommendation.to_csv("bestselling_item_recommendation.csv")
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
print("Recommending Items as per Top Selling Brand from 2017 to 2019:")
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n")
for k in range(len(list_category)):
print(f"For Category: {list_category[k]}, best selling brands are:\n")
sol = best_selling_brand_2years_fun(list_category[k])
for j in range(len(sol[0])):
brand_id = sol[0][j]
brand_rating = sol[1][j]
print(f"Brand Rank {j+1}: {brand_id}")
print(f"Brand Units Sold: {brand_rating}")
print()
bestselling_brand_items_2years(list_category[k], brand_id)
print("_______________________________")
print("-------------------------------")
print()
print(
"________________________________________________________________________________________________"
)
print(
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)
print()
Recommending Items as per Top Selling Brand from 2017 to 2019: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For Category: Portable Audio & Video, best selling brands are: Brand Rank 1: DBPOWER Brand Units Sold: 3033 Item_ID Units Sold 0 4009 2772 1 2864 258 2 4079 3 _______________________________ ------------------------------- Brand Rank 2: Bose Brand Units Sold: 2527 Item_ID Units Sold 0 7022 2043 1 5171 134 2 3195 130 3 5273 106 4 5156 76 _______________________________ ------------------------------- Brand Rank 3: Pyle Brand Units Sold: 677 Item_ID Units Sold 0 3468 148 1 4753 131 2 5445 97 3 33 56 4 5740 49 _______________________________ ------------------------------- Brand Rank 4: Uniden Brand Units Sold: 606 Item_ID Units Sold 0 2223 210 1 2159 170 2 4419 110 3 2434 95 4 2298 6 _______________________________ ------------------------------- Brand Rank 5: Mpow Brand Units Sold: 432 Item_ID Units Sold 0 5748 429 1 5974 3 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Computers & Accessories, best selling brands are: Brand Rank 1: Logitech Brand Units Sold: 6269 Item_ID Units Sold 0 2031 3042 1 647 1170 2 1124 635 3 1780 452 4 3630 241 _______________________________ ------------------------------- Brand Rank 2: Fintie Brand Units Sold: 1161 Item_ID Units Sold 0 8736 585 1 3643 225 2 5200 66 3 7901 57 4 5354 51 _______________________________ ------------------------------- Brand Rank 3: Bose Brand Units Sold: 980 Item_ID Units Sold 0 3106 980 _______________________________ ------------------------------- Brand Rank 4: LSS Brand Units Sold: 424 Item_ID Units Sold 0 3884 184 1 4543 64 2 4271 44 3 3951 43 4 4043 33 _______________________________ ------------------------------- Brand Rank 5: Apple Brand Units Sold: 416 Item_ID Units Sold 0 5364 104 1 5329 83 2 6562 80 3 5405 65 4 4302 49 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Headphones, best selling brands are: Brand Rank 1: Mpow Brand Units Sold: 5832 Item_ID Units Sold 0 6819 3734 1 6689 1592 2 6835 158 3 7809 150 4 5424 43 _______________________________ ------------------------------- Brand Rank 2: Skullcandy Brand Units Sold: 4181 Item_ID Units Sold 0 5178 1107 1 2355 989 2 8195 802 3 5261 287 4 8350 282 _______________________________ ------------------------------- Brand Rank 3: Bose Brand Units Sold: 4108 Item_ID Units Sold 0 5041 1190 1 7828 829 2 4969 812 3 7869 659 4 7645 253 _______________________________ ------------------------------- Brand Rank 4: Sennheiser Brand Units Sold: 3238 Item_ID Units Sold 0 162 2575 1 259 201 2 1242 105 3 2228 72 4 2032 72 _______________________________ ------------------------------- Brand Rank 5: Panasonic Brand Units Sold: 1411 Item_ID Units Sold 0 111 932 1 9510 233 2 9380 107 3 9537 105 4 3248 34 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Camera & Photo, best selling brands are: Brand Rank 1: Neewer Brand Units Sold: 2160 Item_ID Units Sold 0 8341 920 1 1605 522 2 8077 379 3 3783 70 4 7101 57 _______________________________ ------------------------------- Brand Rank 2: Fujifilm Brand Units Sold: 1923 Item_ID Units Sold 0 1258 342 1 7349 198 2 7895 182 3 6444 116 4 3384 110 _______________________________ ------------------------------- Brand Rank 3: Polaroid Brand Units Sold: 1774 Item_ID Units Sold 0 6726 840 1 2586 768 2 2366 92 3 1327 48 4 1531 12 _______________________________ ------------------------------- Brand Rank 4: Nikon Brand Units Sold: 738 Item_ID Units Sold 0 7544 225 1 6745 216 2 8609 58 3 8539 55 4 6599 40 _______________________________ ------------------------------- Brand Rank 5: Canon Brand Units Sold: 447 Item_ID Units Sold 0 9225 141 1 9189 73 2 8484 59 3 220 43 4 6434 27 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Accessories & Supplies, best selling brands are: Brand Rank 1: EldHus Brand Units Sold: 989 Item_ID Units Sold 0 8282 358 1 2138 355 2 9188 70 3 1861 46 4 9169 36 _______________________________ ------------------------------- Brand Rank 2: Etre Jeune Brand Units Sold: 276 Item_ID Units Sold 0 7827 103 1 5081 75 2 9244 27 3 3229 24 4 1473 23 _______________________________ ------------------------------- Brand Rank 3: Jabra Brand Units Sold: 245 Item_ID Units Sold 0 4811 187 1 3049 43 2 2243 11 3 1750 4 _______________________________ ------------------------------- Brand Rank 4: Sennheiser Brand Units Sold: 101 Item_ID Units Sold 0 1560 68 1 4590 33 _______________________________ ------------------------------- Brand Rank 5: Pyle Brand Units Sold: 79 Item_ID Units Sold 0 4225 64 1 1744 9 2 5258 6 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Television & Video, best selling brands are: Brand Rank 1: Bose Brand Units Sold: 201 Item_ID Units Sold 0 5202 201 _______________________________ ------------------------------- Brand Rank 2: DBPOWER Brand Units Sold: 88 Item_ID Units Sold 0 8074 66 1 4633 20 2 2654 2 _______________________________ ------------------------------- Brand Rank 3: Samsung Brand Units Sold: 63 Item_ID Units Sold 0 2129 63 _______________________________ ------------------------------- Brand Rank 4: Pyle Brand Units Sold: 40 Item_ID Units Sold 0 1984 40 _______________________________ ------------------------------- Brand Rank 5: Toshiba Brand Units Sold: 14 Item_ID Units Sold 0 4177 12 1 2173 1 2 2214 1 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Car Electronics & GPS, best selling brands are: Brand Rank 1: Garmin Brand Units Sold: 537 Item_ID Units Sold 0 7936 186 1 5185 83 2 4152 83 3 1105 75 4 6625 58 _______________________________ ------------------------------- Brand Rank 2: Pyle Brand Units Sold: 286 Item_ID Units Sold 0 638 86 1 8041 72 2 8335 60 3 2431 24 4 593 21 _______________________________ ------------------------------- Brand Rank 3: Uniden Brand Units Sold: 163 Item_ID Units Sold 0 1056 143 1 6731 20 _______________________________ ------------------------------- Brand Rank 4: Mpow Brand Units Sold: 24 Item_ID Units Sold 0 5749 24 _______________________________ ------------------------------- Brand Rank 5: EINCAR Brand Units Sold: 10 Item_ID Units Sold 0 6750 10 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Home Audio, best selling brands are: Brand Rank 1: TaoTronics Brand Units Sold: 2541 Item_ID Units Sold 0 5054 1388 1 8375 1099 2 6328 54 _______________________________ ------------------------------- Brand Rank 2: Pyle Brand Units Sold: 595 Item_ID Units Sold 0 1236 116 1 3090 114 2 1125 86 3 827 79 4 5459 77 _______________________________ ------------------------------- Brand Rank 3: Sony Brand Units Sold: 28 Item_ID Units Sold 0 511 28 _______________________________ ------------------------------- Brand Rank 4: Bose Brand Units Sold: 16 Item_ID Units Sold 0 3625 9 1 211 5 2 178 2 _______________________________ ------------------------------- Brand Rank 5: EldHus Brand Units Sold: 7 Item_ID Units Sold 0 6662 7 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Security & Surveillance, best selling brands are: Brand Rank 1: Uniden Brand Units Sold: 243 Item_ID Units Sold 0 3989 175 1 6638 52 2 1250 12 3 3603 4 _______________________________ ------------------------------- Brand Rank 2: Samsung Brand Units Sold: 12 Item_ID Units Sold 0 3293 12 _______________________________ ------------------------------- Brand Rank 3: Funlux Brand Units Sold: 7 Item_ID Units Sold 0 4831 7 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Wearable Technology, best selling brands are: Brand Rank 1: Sony Brand Units Sold: 123 Item_ID Units Sold 0 5402 123 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Dresses, best selling brands are: Brand Rank 1: Chi Chi London Brand Units Sold: 1084 Item_ID Units Sold 0 107539 286 1 126114 148 2 135364 107 3 141856 104 4 147244 86 _______________________________ ------------------------------- Brand Rank 2: ModCloth Brand Units Sold: 848 Item_ID Units Sold 0 70538 187 1 142002 120 2 154064 85 3 150866 71 4 153445 67 _______________________________ ------------------------------- Brand Rank 3: Retrolicious Brand Units Sold: 327 Item_ID Units Sold 0 40141 105 1 119314 79 2 56780 51 3 28252 34 4 140020 34 _______________________________ ------------------------------- Brand Rank 4: Emily and Fin Brand Units Sold: 271 Item_ID Units Sold 0 128563 97 1 153665 92 2 141295 82 _______________________________ ------------------------------- Brand Rank 5: Pepaloves Brand Units Sold: 183 Item_ID Units Sold 0 153481 183 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Outerwear, best selling brands are: Brand Rank 1: ModCloth Brand Units Sold: 384 Item_ID Units Sold 0 135555 73 1 86074 53 2 123500 53 3 58990 49 4 85507 44 _______________________________ ------------------------------- Brand Rank 2: Steve Madden Brand Units Sold: 239 Item_ID Units Sold 0 27439 126 1 110820 45 2 129113 44 3 110824 24 _______________________________ ------------------------------- Brand Rank 3: Jack by BB Dakota Brand Units Sold: 85 Item_ID Units Sold 0 71607 85 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Bottoms, best selling brands are: Brand Rank 1: ModCloth Brand Units Sold: 1642 Item_ID Units Sold 0 21296 150 1 153501 139 2 141880 136 3 54222 116 4 148257 107 _______________________________ ------------------------------- Brand Rank 2: Miss Candyfloss Brand Units Sold: 153 Item_ID Units Sold 0 133399 68 1 121272 56 2 133539 29 _______________________________ ------------------------------- Brand Rank 3: Pink Martini Brand Units Sold: 26 Item_ID Units Sold 0 111781 26 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For Category: Tops, best selling brands are: Brand Rank 1: ModCloth Brand Units Sold: 933 Item_ID Units Sold 0 59176 142 1 40899 141 2 118020 108 3 153726 98 4 153517 87 _______________________________ ------------------------------- Brand Rank 2: Out of Print Brand Units Sold: 52 Item_ID Units Sold 0 67022 37 1 113643 15 _______________________________ ------------------------------- Brand Rank 3: Kin Ship Brand Units Sold: 51 Item_ID Units Sold 0 122266 45 1 70230 6 _______________________________ ------------------------------- Brand Rank 4: Banned Brand Units Sold: 48 Item_ID Units Sold 0 146244 48 _______________________________ ------------------------------- Brand Rank 5: Daisey Natives Brand Units Sold: 38 Item_ID Units Sold 0 143764 38 _______________________________ ------------------------------- ________________________________________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# # bestselling_brand_recommendation
# def bestselling_brand_items_2years_1(category_name, brand_name):
# """this function prints dataframe showing best-selling items & units sold for given category and brand"""
# temp_df = best_selling_item_2years[
# (best_selling_item_2years.brand == brand_name)
# & (best_selling_item_2years.category == category_name)
# ].head()
# item_list = temp_df.item_id.tolist()
# return item_list
# temp_df = pd.DataFrame(
# columns=[
# "Recommendation_System_Type",
# "Category",
# "Brand",
# "Brand_Sales",
# "Top_Products",
# ]
# )
# for k in range(len(list_category)):
# # print(f"For Category: {list_category[k]}, best selling brands are:\n")
# sol = best_selling_brand_2years_fun(list_category[k])
# for j in range(len(sol[0])):
# brand_id = sol[0][j]
# brand_rating = sol[1][j]
# # print(f"Brand Rank {j+1}: {brand_id}")
# # print(f"Brand Rating: {brand_rating}")
# temp_df.loc[len(temp_df)] = [
# "Latest_Bestselling_Brand",
# list_category[k],
# brand_id,
# brand_rating,
# bestselling_brand_items_2years_1(list_category[k], brand_id),
# ]
# bestselling_brand_recommendation = bestselling_brand_recommendation.append(temp_df)
# bestselling_brand_recommendation.to_csv("bestselling_brand_recommendation.csv")
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
This will allow us to link the preferences/likenesses of user to buy an item based on the item purchased before.
For Market Basket Analysis / Apriori, higher the lift value, higher is the chance that the user will buy the consequent item based on the antecedant item, i.e. you can recommend the consequent item bought by the user upon the user selecting the antecedant item.
"""Items bought per category"""
consolidated_db.groupby(by="category", as_index=False).agg({"count": pd.Series.sum})
| category | count | |
|---|---|---|
| 0 | Accessories & Supplies | 158598 |
| 1 | Bottoms | 23625 |
| 2 | Camera & Photo | 192573 |
| 3 | Car Electronics & GPS | 33070 |
| 4 | Computers & Accessories | 322938 |
| 5 | Dresses | 34160 |
| 6 | Headphones | 359334 |
| 7 | Home Audio | 24193 |
| 8 | Outerwear | 7131 |
| 9 | Portable Audio & Video | 143370 |
| 10 | Security & Surveillance | 10806 |
| 11 | Television & Video | 32057 |
| 12 | Tops | 34977 |
| 13 | Wearable Technology | 16015 |
"""We have to convert the item_id and user_id to string"""
consolidated_db.item_id = consolidated_db.item_id.astype("str")
consolidated_db.user_id = consolidated_db.user_id.astype("str")
"""through trial and error, the max value of minimum-support-values which gives association rules are as below:"""
cat_support = {
"Portable Audio & Video": 0.02,
"Computers & Accessories": 0.005,
"Headphones": 0.003,
"Camera & Photo": 0.02,
"Accessories & Supplies": 0.05,
"Television & Video": 0.02,
"Car Electronics & GPS": 0.02,
"Home Audio": 0.05,
"Security & Surveillance": 0.08,
"Wearable Technology": 0.05,
"Dresses": 0.046,
"Outerwear": 0.1,
"Bottoms": 0.05,
"Tops": 0.04,
}
print("Categorical Item Suggestion based on Market Basket Analysis is:")
print()
for category_name in list_category:
consolidated_db_temp = consolidated_db[consolidated_db.category == category_name]
user_transactions_temp = consolidated_db_temp.groupby(
by="user_id", as_index=False
).agg({"count": pd.Series.sum})
user_transactions_temp.columns = ["user_id", "number_of_transactions"]
temp_basket = pd.merge(consolidated_db_temp, user_transactions_temp, on="user_id")
temp_basket = temp_basket[temp_basket.number_of_transactions > 1]
temp_basket["concat_item"] = temp_basket.item_id + "|"
temp_basket_trans = temp_basket.groupby(by="user_id", as_index=False).agg(
{"concat_item": pd.Series.sum}
)
temp_basket_trans.concat_item = [
i.split("|") for i in temp_basket_trans.concat_item.tolist()
]
transactions_list = temp_basket_trans.concat_item.tolist()
transactions_list = [
transactions_list[i][0 : (len(transactions_list[i]) - 1)]
for i in range(len(transactions_list))
]
# We form an array where every column has one separate column with purchase data in rows as boolean
encode = TransactionEncoder()
array_transactions = encode.fit_transform(transactions_list)
# items as columns can be seen via
item_cols = encode.columns_
# We form a dataframe
market_basket_clean = pd.DataFrame(array_transactions, columns=item_cols)
# We apply apriori algorithm to see the connection between items
model = apriori(
market_basket_clean,
min_support=cat_support[category_name],
max_len=5,
use_colnames=True,
)
rule = association_rules(model, metric="lift", min_threshold=1)
print(f"For category: {category_name}")
print()
print(
rule.sort_values(by="lift", ascending=False)[
["antecedents", "consequents", "support", "confidence", "lift"]
]
)
print("____________________________________________________________________")
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
print()
print()
Categorical Item Suggestion based on Market Basket Analysis is: For category: Portable Audio & Video antecedents consequents support confidence lift 0 (1706) (3035) 0.023612 0.477876 15.612895 1 (3035) (1706) 0.023612 0.771429 15.612895 3 (7780) (8711) 0.030171 0.123656 3.008522 2 (8711) (7780) 0.030171 0.734043 3.008522 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Computers & Accessories antecedents consequents support confidence lift 0 (2523) (2486) 0.007543 0.611842 16.876987 1 (2486) (2523) 0.007543 0.208054 16.876987 3 (4718) (274) 0.006732 0.188209 3.683511 2 (274) (4718) 0.006732 0.131746 3.683511 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Headphones antecedents consequents support confidence lift 4 (9315) (7256) 0.003426 0.441441 21.118322 5 (7256) (9315) 0.003426 0.163880 21.118322 2 (111) (6210) 0.003216 0.116751 3.976215 3 (6210) (111) 0.003216 0.109524 3.976215 0 (111) (1575) 0.003985 0.144670 3.477917 1 (1575) (111) 0.003985 0.095798 3.477917 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Camera & Photo antecedents consequents support confidence lift 0 (6726) (2586) 0.037314 0.836830 16.006242 1 (2586) (6726) 0.037314 0.713718 16.006242 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Accessories & Supplies antecedents consequents support confidence lift 4 (3995) (4806) 0.090031 0.559157 3.043594 5 (4806) (3995) 0.090031 0.490057 3.043594 2 (4806) (2483) 0.110647 0.602273 2.989520 3 (2483) (4806) 0.110647 0.549223 2.989520 1 (2483) (3995) 0.072286 0.358808 2.228450 0 (3995) (2483) 0.072286 0.448947 2.228450 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Television & Video antecedents consequents support confidence lift 2 (6078) (9144) 0.021552 0.833333 38.666667 3 (9144) (6078) 0.021552 1.000000 38.666667 0 (3617) (2129) 0.030172 0.368421 2.947368 1 (2129) (3617) 0.030172 0.241379 2.947368 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Car Electronics & GPS antecedents consequents support confidence lift 2 (745) (1115) 0.048780 0.769231 15.769231 3 (1115) (745) 0.048780 1.000000 15.769231 0 (4152) (1105) 0.034146 0.466667 5.314815 1 (1105) (4152) 0.034146 0.388889 5.314815 4 (6005) (3728) 0.024390 0.200000 1.640000 5 (3728) (6005) 0.024390 0.200000 1.640000 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Home Audio antecedents consequents support confidence lift 0 (5054) (6328) 0.062016 0.170213 1.829787 1 (6328) (5054) 0.062016 0.666667 1.829787 2 (5054) (8802) 0.054264 0.148936 1.200798 3 (8802) (5054) 0.054264 0.437500 1.200798 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Security & Surveillance antecedents consequents support confidence lift 2 (5283) (6156) 0.083333 0.500000 3.818182 3 (6156) (5283) 0.083333 0.636364 3.818182 0 (5283) (5456) 0.095238 0.571429 3.000000 1 (5456) (5283) 0.095238 0.500000 3.000000 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Wearable Technology antecedents consequents support confidence lift 0 (4278) (6003) 0.08046 0.538462 3.346154 1 (6003) (4278) 0.08046 0.500000 3.346154 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Dresses antecedents consequents support confidence lift 0 (32406) (16411) 0.046748 0.315068 2.226409 1 (16411) (32406) 0.046748 0.330341 2.226409 2 (32405) (32406) 0.047764 0.306688 2.066996 3 (32406) (32405) 0.047764 0.321918 2.066996 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Outerwear antecedents consequents support confidence lift 4 (27439) (32236) 0.112583 0.431472 1.428778 5 (32236) (27439) 0.112583 0.372807 1.428778 2 (32236) (11960) 0.156291 0.517544 1.400522 3 (11960) (32236) 0.156291 0.422939 1.400522 0 (27439) (11960) 0.119205 0.456853 1.236286 1 (11960) (27439) 0.119205 0.322581 1.236286 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Bottoms antecedents consequents support confidence lift 6 (80238) (62447) 0.055031 0.366876 2.466526 7 (62447) (80238) 0.055031 0.369979 2.466526 2 (21296) (54222) 0.055346 0.243430 2.058798 3 (54222) (21296) 0.055346 0.468085 2.058798 0 (21296) (50818) 0.057862 0.254495 1.675558 1 (50818) (21296) 0.057862 0.380952 1.675558 4 (21296) (62447) 0.052516 0.230982 1.552902 5 (62447) (21296) 0.052516 0.353066 1.552902 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX For category: Tops antecedents consequents support confidence lift 0 (40899) (34935) 0.041047 0.391304 2.185324 1 (34935) (40899) 0.041047 0.229236 2.185324 2 (57369) (34935) 0.040254 0.351820 1.964814 3 (34935) (57369) 0.040254 0.224806 1.964814 ____________________________________________________________________ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# # print("Categorical Item Suggestion based on Market Basket Analysis is:")
# # print()
# apriori_item_df = pd.DataFrame(columns=["antecedents", "consequents", "support", "confidence", "lift", "Category"])
# for category_name in list_category:
# consolidated_db_temp = consolidated_db[consolidated_db.category == category_name]
# user_transactions_temp = consolidated_db_temp.groupby(
# by="user_id", as_index=False
# ).agg({"count": pd.Series.sum})
# user_transactions_temp.columns = ["user_id", "number_of_transactions"]
# temp_basket = pd.merge(consolidated_db_temp, user_transactions_temp, on="user_id")
# temp_basket = temp_basket[temp_basket.number_of_transactions > 1]
# temp_basket["concat_item"] = temp_basket.item_id + "|"
# temp_basket_trans = temp_basket.groupby(by="user_id", as_index=False).agg(
# {"concat_item": pd.Series.sum}
# )
# temp_basket_trans.concat_item = [
# i.split("|") for i in temp_basket_trans.concat_item.tolist()
# ]
# transactions_list = temp_basket_trans.concat_item.tolist()
# transactions_list = [
# transactions_list[i][0 : (len(transactions_list[i]) - 1)]
# for i in range(len(transactions_list))
# ]
# # We form an array where every column has one separate column with purchase data in rows as boolean
# encode = TransactionEncoder()
# array_transactions = encode.fit_transform(transactions_list)
# # items as columns can be seen via
# item_cols = encode.columns_
# # We form a dataframe
# market_basket_clean = pd.DataFrame(array_transactions, columns=item_cols)
# # We apply apriori algorithm to see the connection between items
# model = apriori(
# market_basket_clean,
# min_support=cat_support[category_name],
# max_len=5,
# use_colnames=True,
# )
# rule = association_rules(model, metric="lift", min_threshold=1)
# # print(f"For category: {category_name}")
# # print()
# rule = rule.sort_values(by="lift", ascending=False)[
# ["antecedents", "consequents", "support", "confidence", "lift"]
# ]
# # print("____________________________________________________________________")
# # print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
# # print()
# # print()
# rule["Category"] = category_name
# apriori_item_df = apriori_item_df.append(rule)
# apriori_item_df.to_csv("apriori_item.csv")
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
"""We will be considering dataframes: select_electronics_db & select_modcloth_db"""
select_electronics_db["count"] = 1
select_modcloth_db["count"] = 1
"""Forming a dataframe of electronics and modcloth transactions per user"""
electronics_temp = select_electronics_db.groupby(by="user_id", as_index=False).agg(
{"count": pd.Series.sum}
)
modcloth_temp = select_modcloth_db.groupby(by="user_id", as_index=False).agg(
{"count": pd.Series.sum}
)
"""We will rename the column 'count' to 'transactions' to avoid any confusion as we will be merging this dataframe
with parent databrame"""
electronics_temp.rename(columns={"count": "transactions"}, inplace=True)
modcloth_temp.rename(columns={"count": "transactions"}, inplace=True)
"""merging this dataframe with parent dataframe"""
select_electronics_db = pd.merge(select_electronics_db, electronics_temp, on="user_id")
select_modcloth_db = pd.merge(select_modcloth_db, modcloth_temp, on="user_id")
<ipython-input-89-a1ede762dd03>:2: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy <ipython-input-89-a1ede762dd03>:3: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
"""dropping users with only 1 transaction"""
select_electronics_db = select_electronics_db[select_electronics_db.transactions > 1]
select_modcloth_db = select_modcloth_db[select_modcloth_db.transactions > 1]
select_electronics_db.head(2)
| item_id | user_id | rating | timestamp | category | brand | count | transactions | |
|---|---|---|---|---|---|---|---|---|
| 7 | 0 | 7 | 2.0 | 1999-07-13 | Portable Audio & Video | Other | 1 | 3 |
| 8 | 2205 | 7 | 5.0 | 2015-06-18 | Computers & Accessories | Other | 1 | 3 |
select_modcloth_db.head(2)
| item_id | user_id | rating | timestamp | category | brand | count | transactions | |
|---|---|---|---|---|---|---|---|---|
| 0 | 7443 | Alex | 4 | 2010-01-21 08:00:00+00:00 | Dresses | Other | 1 | 66 |
| 1 | 21296 | Alex | 5 | 2011-10-13 07:00:00+00:00 | Bottoms | ModCloth | 1 | 66 |
temp_db_cat = select_electronics_db.copy()
temp_db_cat["concat_cat"] = temp_db_cat.category + "|"
temp_db_cat = temp_db_cat.groupby(by="user_id", as_index=False).agg(
{"concat_cat": pd.Series.sum}
)
temp_db_cat.concat_cat = [i.split("|") for i in temp_db_cat.concat_cat]
# to remove duplicates in the transaction, we use the 'set' type casting on the list before converting it back to list
temp_db_cat.concat_cat = [list(set(i[: len(i) - 1])) for i in temp_db_cat.concat_cat]
# this will have certain users where the user has purchases items from only one category and not from 2 or more categories
# for forming association rules, we have to consider cases where user has purchased items from 2 or more categories
temp_db_cat["cat_num"] = [len(i) for i in temp_db_cat.concat_cat]
temp_db_cat = temp_db_cat[temp_db_cat.cat_num > 1]
category_transaction_list = temp_db_cat.concat_cat.tolist()
encode_cat = TransactionEncoder()
array_transactions_cat = encode_cat.fit_transform(category_transaction_list)
# items as columns can be seen via
cat_cols = encode_cat.columns_
# We form a dataframe of categories
market_basket_cat_clean = pd.DataFrame(array_transactions_cat, columns=cat_cols)
# We apply apriori algorithm to see the connection between items
model_cat = apriori(
market_basket_cat_clean, min_support=0.0013, max_len=5, use_colnames=True
)
rule_cat = association_rules(model_cat, metric="lift", min_threshold=1)
rule_cat.sort_values(by="lift", ascending=False)[
["antecedents", "consequents", "confidence", "lift"]
]
| antecedents | consequents | confidence | lift | |
|---|---|---|---|---|
| 13 | (Headphones, Camera & Photo, Accessories & Sup... | (Computers & Accessories, Portable Audio & Video) | 0.127848 | 1.601001 |
| 32 | (Computers & Accessories, Portable Audio & Video) | (Headphones, Camera & Photo, Accessories & Sup... | 0.017095 | 1.601001 |
| 28 | (Portable Audio & Video, Accessories & Supplies) | (Headphones, Camera & Photo, Computers & Acces... | 0.032053 | 1.586243 |
| 17 | (Headphones, Camera & Photo, Computers & Acces... | (Portable Audio & Video, Accessories & Supplies) | 0.067559 | 1.586243 |
| 21 | (Computers & Accessories, Portable Audio & Vid... | (Headphones, Camera & Photo) | 0.158307 | 1.541079 |
| 24 | (Headphones, Camera & Photo) | (Computers & Accessories, Portable Audio & Vid... | 0.013289 | 1.541079 |
| 36 | (Portable Audio & Video) | (Headphones, Camera & Photo, Computers & Acces... | 0.005709 | 1.441663 |
| 9 | (Headphones, Camera & Photo, Computers & Acces... | (Portable Audio & Video) | 0.344710 | 1.441663 |
| 15 | (Headphones, Computers & Accessories, Accessor... | (Camera & Photo, Portable Audio & Video) | 0.061736 | 1.416710 |
| 30 | (Camera & Photo, Portable Audio & Video) | (Headphones, Computers & Accessories, Accessor... | 0.031328 | 1.416710 |
| 18 | (Headphones, Computers & Accessories, Portable... | (Camera & Photo, Accessories & Supplies) | 0.082991 | 1.408581 |
| 27 | (Camera & Photo, Accessories & Supplies) | (Headphones, Computers & Accessories, Portable... | 0.023170 | 1.408581 |
| 19 | (Camera & Photo, Portable Audio & Video, Acces... | (Headphones, Computers & Accessories) | 0.299703 | 1.334371 |
| 26 | (Headphones, Computers & Accessories) | (Camera & Photo, Portable Audio & Video, Acces... | 0.006078 | 1.334371 |
| 10 | (Headphones, Computers & Accessories, Portable... | (Camera & Photo) | 0.384030 | 1.287597 |
| 35 | (Camera & Photo) | (Headphones, Computers & Accessories, Portable... | 0.004577 | 1.287597 |
| 1 | (Accessories & Supplies) | (Wearable Technology) | 0.042844 | 1.266386 |
| 0 | (Wearable Technology) | (Accessories & Supplies) | 0.407111 | 1.266386 |
| 22 | (Camera & Photo, Portable Audio & Video, Compu... | (Headphones, Accessories & Supplies) | 0.151198 | 1.259566 |
| 23 | (Headphones, Accessories & Supplies) | (Camera & Photo, Portable Audio & Video, Compu... | 0.011373 | 1.259566 |
| 31 | (Camera & Photo, Computers & Accessories) | (Headphones, Portable Audio & Video, Accessori... | 0.011210 | 1.254680 |
| 14 | (Headphones, Portable Audio & Video, Accessori... | (Camera & Photo, Computers & Accessories) | 0.152799 | 1.254680 |
| 16 | (Headphones, Camera & Photo, Portable Audio & ... | (Computers & Accessories, Accessories & Supplies) | 0.150522 | 1.207961 |
| 29 | (Computers & Accessories, Accessories & Supplies) | (Headphones, Camera & Photo, Portable Audio & ... | 0.010956 | 1.207961 |
| 8 | (Headphones, Camera & Photo, Portable Audio & ... | (Computers & Accessories) | 0.627329 | 1.198820 |
| 37 | (Computers & Accessories) | (Headphones, Camera & Photo, Portable Audio & ... | 0.002609 | 1.198820 |
| 12 | (Camera & Photo, Portable Audio & Video, Compu... | (Headphones) | 0.608434 | 1.165662 |
| 33 | (Headphones) | (Camera & Photo, Portable Audio & Video, Compu... | 0.002615 | 1.165662 |
| 7 | (Computers & Accessories) | (Headphones, Camera & Photo, Television & Video) | 0.002738 | 1.164167 |
| 2 | (Headphones, Camera & Photo, Television & Video) | (Computers & Accessories) | 0.609195 | 1.164167 |
| 3 | (Headphones, Camera & Photo, Computers & Acces... | (Television & Video) | 0.070903 | 1.114207 |
| 6 | (Television & Video) | (Headphones, Camera & Photo, Computers & Acces... | 0.022515 | 1.114207 |
| 25 | (Headphones, Portable Audio & Video) | (Camera & Photo, Computers & Accessories, Acce... | 0.013725 | 1.095370 |
| 20 | (Camera & Photo, Computers & Accessories, Acce... | (Headphones, Portable Audio & Video) | 0.108954 | 1.095370 |
| 11 | (Headphones, Camera & Photo, Portable Audio & ... | (Accessories & Supplies) | 0.350694 | 1.090892 |
| 34 | (Accessories & Supplies) | (Headphones, Camera & Photo, Portable Audio & ... | 0.004247 | 1.090892 |
| 5 | (Camera & Photo) | (Headphones, Computers & Accessories, Televisi... | 0.004804 | 1.027174 |
| 4 | (Headphones, Computers & Accessories, Televisi... | (Camera & Photo) | 0.306358 | 1.027174 |
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# temp_db_cat = select_electronics_db.copy()
# temp_db_cat["concat_cat"] = temp_db_cat.category + "|"
# temp_db_cat = temp_db_cat.groupby(by="user_id", as_index=False).agg(
# {"concat_cat": pd.Series.sum}
# )
# temp_db_cat.concat_cat = [i.split("|") for i in temp_db_cat.concat_cat]
# # to remove duplicates in the transaction, we use the 'set' type casting on the list before converting it back to list
# temp_db_cat.concat_cat = [list(set(i[: len(i) - 1])) for i in temp_db_cat.concat_cat]
# # this will have certain users where the user has purchases items from only one category and not from 2 or more categories
# # for forming association rules, we have to consider cases where user has purchased items from 2 or more categories
# temp_db_cat["cat_num"] = [len(i) for i in temp_db_cat.concat_cat]
# temp_db_cat = temp_db_cat[temp_db_cat.cat_num > 1]
# category_transaction_list = temp_db_cat.concat_cat.tolist()
# encode_cat = TransactionEncoder()
# array_transactions_cat = encode_cat.fit_transform(category_transaction_list)
# # items as columns can be seen via
# cat_cols = encode_cat.columns_
# # We form a dataframe of categories
# market_basket_cat_clean = pd.DataFrame(array_transactions_cat, columns=cat_cols)
# # We apply apriori algorithm to see the connection between items
# model_cat = apriori(
# market_basket_cat_clean, min_support=0.0013, max_len=5, use_colnames=True
# )
# rule_cat = association_rules(model_cat, metric="lift", min_threshold=1)
# rule_cat = rule_cat.sort_values(by="lift", ascending=False)[
# ["antecedents", "consequents", "confidence", "lift"]
# ]
# apriori_category = rule_cat.copy()
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'
temp_db_cat = select_modcloth_db.copy()
temp_db_cat["concat_cat"] = temp_db_cat.category + "|"
temp_db_cat = temp_db_cat.groupby(by="user_id", as_index=False).agg(
{"concat_cat": pd.Series.sum}
)
temp_db_cat.concat_cat = [i.split("|") for i in temp_db_cat.concat_cat]
# to remove duplicates in the transaction, we use the 'set' type casting on the list before converting it back to list
temp_db_cat.concat_cat = [list(set(i[: len(i) - 1])) for i in temp_db_cat.concat_cat]
# this will have certain users where the user has purchases items from only one category and not from 2 or more categories
# for forming association rules, we have to consider cases where user has purchased items from 2 or more categories
temp_db_cat["cat_num"] = [len(i) for i in temp_db_cat.concat_cat]
temp_db_cat = temp_db_cat[temp_db_cat.cat_num > 1]
category_transaction_list = temp_db_cat.concat_cat.tolist()
encode_cat = TransactionEncoder()
array_transactions_cat = encode_cat.fit_transform(category_transaction_list)
# items as columns can be seen via
cat_cols = encode_cat.columns_
# We form a dataframe of categories
market_basket_cat_clean = pd.DataFrame(array_transactions_cat, columns=cat_cols)
# We apply apriori algorithm to see the connection between items
model_cat = apriori(
market_basket_cat_clean, min_support=0.09, max_len=5, use_colnames=True
)
rule_cat = association_rules(model_cat, metric="lift", min_threshold=1)
rule_cat.sort_values(by="lift", ascending=False)[
["antecedents", "consequents", "confidence", "lift"]
]
| antecedents | consequents | confidence | lift | |
|---|---|---|---|---|
| 3 | (Dresses, Bottoms, Tops) | (Outerwear) | 0.408913 | 1.430131 |
| 10 | (Outerwear) | (Dresses, Bottoms, Tops) | 0.340495 | 1.430131 |
| 6 | (Outerwear, Tops) | (Dresses, Bottoms) | 0.482918 | 1.229786 |
| 7 | (Dresses, Bottoms) | (Outerwear, Tops) | 0.247926 | 1.229786 |
| 1 | (Outerwear, Dresses, Tops) | (Bottoms) | 0.771956 | 1.203933 |
| 12 | (Bottoms) | (Outerwear, Dresses, Tops) | 0.151836 | 1.203933 |
| 4 | (Outerwear, Dresses) | (Bottoms, Tops) | 0.536135 | 1.171256 |
| 9 | (Bottoms, Tops) | (Outerwear, Dresses) | 0.212688 | 1.171256 |
| 5 | (Outerwear, Bottoms) | (Dresses, Tops) | 0.585666 | 1.157542 |
| 8 | (Dresses, Tops) | (Outerwear, Bottoms) | 0.192421 | 1.157542 |
| 2 | (Outerwear, Bottoms, Tops) | (Dresses) | 0.794229 | 1.132625 |
| 11 | (Dresses) | (Outerwear, Bottoms, Tops) | 0.138837 | 1.132625 |
| 13 | (Tops) | (Outerwear, Dresses, Bottoms) | 0.125480 | 1.118801 |
| 0 | (Outerwear, Dresses, Bottoms) | (Tops) | 0.868050 | 1.118801 |
"""Below code is to create the website for demonstration of Recommendation System, Hence it is commented out"""
# temp_db_cat = select_modcloth_db.copy()
# temp_db_cat["concat_cat"] = temp_db_cat.category + "|"
# temp_db_cat = temp_db_cat.groupby(by="user_id", as_index=False).agg(
# {"concat_cat": pd.Series.sum}
# )
# temp_db_cat.concat_cat = [i.split("|") for i in temp_db_cat.concat_cat]
# # to remove duplicates in the transaction, we use the 'set' type casting on the list before converting it back to list
# temp_db_cat.concat_cat = [list(set(i[: len(i) - 1])) for i in temp_db_cat.concat_cat]
# # this will have certain users where the user has purchases items from only one category and not from 2 or more categories
# # for forming association rules, we have to consider cases where user has purchased items from 2 or more categories
# temp_db_cat["cat_num"] = [len(i) for i in temp_db_cat.concat_cat]
# temp_db_cat = temp_db_cat[temp_db_cat.cat_num > 1]
# category_transaction_list = temp_db_cat.concat_cat.tolist()
# encode_cat = TransactionEncoder()
# array_transactions_cat = encode_cat.fit_transform(category_transaction_list)
# # items as columns can be seen via
# cat_cols = encode_cat.columns_
# # We form a dataframe of categories
# market_basket_cat_clean = pd.DataFrame(array_transactions_cat, columns=cat_cols)
# # We apply apriori algorithm to see the connection between items
# model_cat = apriori(
# market_basket_cat_clean, min_support=0.09, max_len=5, use_colnames=True
# )
# rule_cat = association_rules(model_cat, metric="lift", min_threshold=1)
# rule_cat = rule_cat.sort_values(by="lift", ascending=False)[
# ["antecedents", "consequents", "confidence", "lift"]
# ]
# apriori_category = apriori_category.append(rule_cat)
# apriori_category.to_csv("apriori_category.csv")
'Below code is to create the website for demonstration of Recommendation System, Hence it is commented out'